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" }
 
  11         { :path => "/api/0.6/notes/1/subscription", :method => :delete },
 
  12         { :controller => "api/note_subscriptions", :action => "destroy", :note_id => "1" }
 
  18       auth_header = bearer_authorization_header user
 
  19       note = create(:note_with_comments)
 
  20       assert_empty note.subscribers
 
  22       assert_difference "NoteSubscription.count", 1 do
 
  23         assert_difference "note.subscribers.count", 1 do
 
  24           post api_note_subscription_path(note), :headers => auth_header
 
  25           assert_response :success
 
  28       assert_equal user, note.subscribers.last
 
  31     def test_create_fail_anonymous
 
  32       note = create(:note_with_comments)
 
  34       assert_no_difference "NoteSubscription.count" do
 
  35         assert_no_difference "note.subscribers.count" do
 
  36           post api_note_subscription_path(note)
 
  37           assert_response :unauthorized
 
  42     def test_create_fail_no_scope
 
  44       auth_header = bearer_authorization_header user, :scopes => %w[read_prefs]
 
  45       note = create(:note_with_comments)
 
  47       assert_no_difference "NoteSubscription.count" do
 
  48         assert_no_difference "note.subscribers.count" do
 
  49           post api_note_subscription_path(note), :headers => auth_header
 
  50           assert_response :forbidden
 
  55     def test_create_fail_note_not_found
 
  57       auth_header = bearer_authorization_header user
 
  59       assert_no_difference "NoteSubscription.count" do
 
  60         post api_note_subscription_path(999111), :headers => auth_header
 
  61         assert_response :not_found
 
  63       assert_match "not found", @response.body
 
  66     def test_create_fail_already_subscribed
 
  68       auth_header = bearer_authorization_header user
 
  69       note = create(:note_with_comments)
 
  70       create(:note_subscription, :user => user, :note => note)
 
  72       assert_no_difference "NoteSubscription.count" do
 
  73         assert_no_difference "note.subscribers.count" do
 
  74           post api_note_subscription_path(note), :headers => auth_header
 
  75           assert_response :conflict
 
  78       assert_match "already subscribed", @response.body
 
  83       auth_header = bearer_authorization_header user
 
  84       other_user = create(:user)
 
  85       note = create(:note_with_comments)
 
  86       other_note = create(:note_with_comments)
 
  87       create(:note_subscription, :user => user, :note => note)
 
  88       create(:note_subscription, :user => other_user, :note => note)
 
  89       create(:note_subscription, :user => user, :note => other_note)
 
  91       assert_difference "NoteSubscription.count", -1 do
 
  92         assert_difference "note.subscribers.count", -1 do
 
  93           delete api_note_subscription_path(note), :headers => auth_header
 
  94           assert_response :success
 
  98       assert_equal [other_user], note.subscribers
 
  99       assert_equal [user], other_note.subscribers
 
 102     def test_destroy_fail_anonymous
 
 103       note = create(:note_with_comments)
 
 105       delete api_note_subscription_path(note)
 
 106       assert_response :unauthorized
 
 109     def test_destroy_fail_no_scope
 
 111       auth_header = bearer_authorization_header user, :scopes => %w[read_prefs]
 
 112       note = create(:note_with_comments)
 
 113       create(:note_subscription, :user => user, :note => note)
 
 115       assert_no_difference "NoteSubscription.count" do
 
 116         assert_no_difference "note.subscribers.count" do
 
 117           delete api_note_subscription_path(note), :headers => auth_header
 
 118           assert_response :forbidden
 
 123     def test_destroy_fail_note_not_found
 
 125       auth_header = bearer_authorization_header user
 
 127       delete api_note_subscription_path(999111), :headers => auth_header
 
 128       assert_response :not_found
 
 129       assert_match "not found", @response.body
 
 132     def test_destroy_fail_not_subscribed
 
 134       auth_header = bearer_authorization_header user
 
 135       note = create(:note_with_comments)
 
 137       delete api_note_subscription_path(note), :headers => auth_header
 
 138       assert_response :not_found
 
 139       assert_match "not subscribed", @response.body