3 class ChangesetSubscriptionsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/changeset/1/subscription", :method => :get },
9 { :controller => "changeset_subscriptions", :action => "show", :changeset_id => "1" }
12 { :path => "/changeset/1/subscription", :method => :post },
13 { :controller => "changeset_subscriptions", :action => "create", :changeset_id => "1" }
16 { :path => "/changeset/1/subscription", :method => :delete },
17 { :controller => "changeset_subscriptions", :action => "destroy", :changeset_id => "1" }
20 get "/changeset/1/subscribe"
21 assert_redirected_to "/changeset/1/subscription"
23 get "/changeset/1/unsubscribe"
24 assert_redirected_to "/changeset/1/subscription"
27 def test_show_as_anonymous
28 changeset = create(:changeset)
30 get changeset_subscription_path(changeset)
31 assert_redirected_to login_path(:referer => changeset_subscription_path(changeset))
34 def test_show_when_not_subscribed
36 other_user = create(:user)
37 changeset = create(:changeset, :user => user)
39 session_for(other_user)
40 get changeset_subscription_path(changeset)
42 assert_response :success
43 assert_dom ".content-body" do
44 assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}"
45 assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
47 assert_dom "> @action", changeset_subscription_path(changeset)
48 assert_dom "input[type=submit]" do
49 assert_dom "> @value", "Subscribe to discussion"
55 def test_show_when_subscribed
57 other_user = create(:user)
58 changeset = create(:changeset, :user => user)
59 changeset.subscribers << other_user
61 session_for(other_user)
62 get changeset_subscription_path(changeset)
64 assert_response :success
65 assert_dom ".content-body" do
66 assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}"
67 assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
69 assert_dom "> @action", changeset_subscription_path(changeset)
70 assert_dom "input[type=submit]" do
71 assert_dom "> @value", "Unsubscribe from discussion"
77 def test_create_success
79 other_user = create(:user)
80 changeset = create(:changeset, :user => user)
82 session_for(other_user)
83 assert_difference "changeset.subscribers.count", 1 do
84 post changeset_subscription_path(changeset)
86 assert_redirected_to changeset_path(changeset)
87 assert changeset.reload.subscribed?(other_user)
92 other_user = create(:user)
93 changeset = create(:changeset, :user => user)
94 changeset.subscribers << other_user
97 assert_no_difference "changeset.subscribers.count" do
98 post changeset_subscription_path(changeset)
100 assert_response :forbidden
102 session_for(other_user)
105 post changeset_subscription_path(999111)
106 assert_response :not_found
108 # trying to subscribe when already subscribed
109 assert_no_difference "changeset.subscribers.count" do
110 post changeset_subscription_path(changeset)
114 def test_destroy_success
116 other_user = create(:user)
117 changeset = create(:changeset, :user => user)
118 changeset.subscribers << other_user
120 session_for(other_user)
121 assert_difference "changeset.subscribers.count", -1 do
122 delete changeset_subscription_path(changeset)
124 assert_redirected_to changeset_path(changeset)
125 assert_not changeset.reload.subscribed?(other_user)
128 def test_unsubscribe_fail
130 other_user = create(:user)
131 changeset = create(:changeset, :user => user)
134 assert_no_difference "changeset.subscribers.count" do
135 delete changeset_subscription_path(changeset)
137 assert_response :forbidden
139 session_for(other_user)
142 delete changeset_subscription_path(999111)
143 assert_response :not_found
145 # trying to unsubscribe when not subscribed
146 assert_no_difference "changeset.subscribers.count" do
147 delete changeset_subscription_path(changeset)