4 class NoteSubscriptionsControllerTest < ActionDispatch::IntegrationTest
7 { :path => "/api/0.6/notes/1/subscription", :method => :post },
8 { :controller => "api/note_subscriptions", :action => "create", :note_id => "1" }
14 auth_header = bearer_authorization_header user
15 note = create(:note_with_comments)
16 assert_empty note.subscribers
18 assert_difference "NoteSubscription.count", 1 do
19 assert_difference "note.subscribers.count", 1 do
20 post api_note_subscription_path(note), :headers => auth_header
21 assert_response :success
24 assert_equal user, note.subscribers.last
27 def test_create_fail_anonymous
28 note = create(:note_with_comments)
30 assert_no_difference "NoteSubscription.count" do
31 assert_no_difference "note.subscribers.count" do
32 post api_note_subscription_path(note)
33 assert_response :unauthorized
38 def test_create_fail_no_scope
40 auth_header = bearer_authorization_header user, :scopes => %w[read_prefs]
41 note = create(:note_with_comments)
43 assert_no_difference "NoteSubscription.count" do
44 assert_no_difference "note.subscribers.count" do
45 post api_note_subscription_path(note), :headers => auth_header
46 assert_response :forbidden
51 def test_create_fail_note_not_found
53 auth_header = bearer_authorization_header user
55 assert_no_difference "NoteSubscription.count" do
56 post api_note_subscription_path(999111), :headers => auth_header
57 assert_response :not_found
59 assert_match "not found", @response.body
62 def test_create_fail_already_subscribed
64 auth_header = bearer_authorization_header user
65 note = create(:note_with_comments)
66 create(:note_subscription, :user => user, :note => note)
68 assert_no_difference "NoteSubscription.count" do
69 assert_no_difference "note.subscribers.count" do
70 post api_note_subscription_path(note), :headers => auth_header
71 assert_response :conflict
74 assert_match "already subscribed", @response.body