-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add notes to history #85
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
efe95c0
Rename 'History' to 'History & Notes'
bishboria d83ad30
Add note model
bishboria 17519e5
Add notes controller
bishboria 49378be
UI and integration test changes to show notes
bishboria cc4a834
Bump gds-api-adapter version to add create_note
bishboria fb623c3
Expose errors in Maslow note model from Need API
bishboria 812919d
Update notes tests to show errors from Need API
bishboria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'gds_api/need_api' | ||
require 'plek' | ||
require 'json' | ||
|
||
class NotesController < ApplicationController | ||
def create | ||
text = params["notes"]["text"] | ||
need_id = params["need_id"] | ||
@note = Note.new(text, need_id, current_user) | ||
|
||
if @note.save | ||
flash[:notice] = "Note saved" | ||
else | ||
flash[:error] = "Error saving note" | ||
end | ||
redirect_to revisions_need_path(need_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Note | ||
|
||
attr_reader :text, :need_id, :author | ||
|
||
def initialize(text, need_id, author) | ||
@text = text | ||
@need_id = need_id | ||
@author = author | ||
end | ||
|
||
def save | ||
note_atts = { | ||
"text" => text, | ||
"need_id" => need_id, | ||
"author" => author_atts(author) | ||
} | ||
Maslow.need_api.create_note(note_atts) | ||
true | ||
rescue GdsApi::HTTPErrorResponse => err | ||
false | ||
end | ||
|
||
private | ||
|
||
def author_atts(author) | ||
{ | ||
"name" => author.name, | ||
"email" => author.email, | ||
"uid" => author.uid | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,15 +46,37 @@ | |
"goal": [ "apply for a secondary school place" ,"apply for a primary school place" ], | ||
"role": [ null, "parent" ] | ||
}, | ||
"created_at": "2013-05-01T13:00:00+00:00" | ||
"created_at": "2013-05-01T13:00:00+00:00", | ||
"notes": [ | ||
{ | ||
"text": "hello", | ||
"author": { | ||
"name": "Donald Duck", | ||
"email": null, | ||
"uid": null | ||
}, | ||
"created_at": "2013-05-02T13:00:00+00:00" | ||
} | ||
] | ||
}, | ||
{ | ||
"action_type": "update", | ||
"author": null, | ||
"changes": { | ||
"legislation": [ "foo", "bar" ] | ||
}, | ||
"created_at": "2013-04-01T13:00:00+00:00" | ||
"created_at": "2013-04-01T13:00:00+00:00", | ||
"notes": [ | ||
{ | ||
"text": "goodbye", | ||
"author": { | ||
"name": "Minnie Mouse", | ||
"email": null, | ||
"uid": null | ||
}, | ||
"created_at": "2013-04-03T13:00:00+00:00" | ||
} | ||
] | ||
}, | ||
{ | ||
"action_type": "create", | ||
|
@@ -67,7 +89,18 @@ | |
"goal": [ "apply for a school place", "apply for a secondary school place" ], | ||
"role": [ "grandparent", null ] | ||
}, | ||
"created_at": "2013-01-01T13:00:00+00:00" | ||
"created_at": "2013-01-01T13:00:00+00:00", | ||
"notes": [ | ||
{ | ||
"text": "oops", | ||
"author": { | ||
"name": "Goofy", | ||
"email": null, | ||
"uid": null | ||
}, | ||
"created_at": "2013-01-02T13:00:00+00:00" | ||
} | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm really not a fan of using fixtures for test data; this ought to be created dynamically by builder code. But that's a bigger change and not part of this PR. |
||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require_relative '../integration_test_helper' | ||
require 'gds_api/test_helpers/need_api' | ||
|
||
class NotesControllerTest < ActionController::TestCase | ||
include GdsApi::TestHelpers::NeedApi | ||
|
||
setup do | ||
login_as stub_user | ||
@note_atts = { | ||
"notes" => { | ||
"text" => "test" | ||
}, | ||
"need_id" => "100001" | ||
} | ||
end | ||
|
||
context "POST create" do | ||
should "be successful" do | ||
GdsApi::NeedApi.any_instance.expects(:create_note).with( | ||
"text" => "test", | ||
"need_id" => "100001", | ||
"author" => { | ||
"name" => stub_user.name, | ||
"email" => stub_user.email, | ||
"uid" => stub_user.uid | ||
} | ||
) | ||
|
||
post :create, @note_atts | ||
|
||
assert_redirected_to revisions_need_path("100001") | ||
assert_equal "Note saved", @controller.flash[:notice] | ||
refute @controller.flash[:error] | ||
end | ||
|
||
should "return an error message if the save fails" do | ||
Note.any_instance.expects(:save).returns(false) | ||
|
||
post :create, @note_atts | ||
|
||
assert_equal "Error saving note", @controller.flash[:error] | ||
refute @controller.flash[:notice] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require_relative '../test_helper' | ||
|
||
class NoteTest < ActiveSupport::TestCase | ||
should "send note data to the need api" do | ||
@author = OpenStruct.new( | ||
name: "Winston Smith-Churchill", | ||
email: "winston@alphagov.co.uk", | ||
uid: "win5t0n" | ||
) | ||
|
||
GdsApi::NeedApi.any_instance.expects(:create_note).with( | ||
"text" => "test", | ||
"need_id" => "100001", | ||
"author" => { | ||
"name" => "Winston Smith-Churchill", | ||
"email" => "winston@alphagov.co.uk", | ||
"uid" => "win5t0n" | ||
} | ||
) | ||
|
||
Note.new("test", "100001", @author).save | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit cryptic; now that the API returns specific errors, could these be displayed to the user?