Skip to content

Commit

Permalink
Merge pull request #592 from alphagov/fix-clearing-notes
Browse files Browse the repository at this point in the history
Fix clearing the petition notes field
  • Loading branch information
pixeltrix authored Jun 2, 2017
2 parents 308ba54 + 8229a6e commit 535ac1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ class Note < ActiveRecord::Base
belongs_to :petition, touch: true

validates :petition, presence: true
validates :details, presence: true
end
16 changes: 16 additions & 0 deletions features/admin/notes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ Feature: A moderator user updates records notes
Then I should be on the admin petition page for "Solidarity with the Unions"
And I follow "Notes"
Then I should see "I think we can debate this, will check with unions select committee first"

Scenario: Removing notes
Given an open petition exists with action: "Solidarity with the Unions"
When I am on the admin all petitions page
And I follow "Solidarity with the Unions"
And I follow "Notes"
Then I should see a "Notes" textarea field
And the markup should be valid
When I fill in "Notes" with "I think we can debate this, will check with unions select committee first"
And I press "Save"
Then I should be on the admin petition page for "Solidarity with the Unions"
And I follow "Notes"
Then I should see "I think we can debate this, will check with unions select committee first"
When I fill in "Notes" with ""
And I press "Save"
Then I should be on the admin petition page for "Solidarity with the Unions"
20 changes: 0 additions & 20 deletions spec/controllers/admin/notes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,6 @@ def do_patch(overrides = {})
expect(petition.note.details).to eq notes_attributes[:details]
end
end

describe 'with invalid params' do
it 're-renders the notes/show template' do
do_patch(note: { details: "" })
expect(response).to be_success
expect(response).to render_template('petitions/show')
end

it 'leaves the in-memory instance with errors' do
do_patch(note: { details: "" })
expect(assigns(:note)).to be_present
expect(assigns(:note).errors).not_to be_empty
end

it 'does not stores the supplied notes in the db' do
do_patch(note: { details: "" })
petition.reload
expect(petition.note).to be_nil
end
end
end

describe 'for an open petition' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
subject { FactoryGirl.build(:note) }

it { is_expected.to validate_presence_of(:petition) }
it { is_expected.to validate_presence_of(:details) }
it { is_expected.not_to validate_presence_of(:details) }
end
end

0 comments on commit 535ac1c

Please sign in to comment.