Skip to content

Commit 9ee2c18

Browse files
committed
Add spec for topics suggest/unsuggest authorize, fix ruby-china#223
1 parent d816020 commit 9ee2c18

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

spec/controllers/topics_controller_spec.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
let(:topic) { Factory :topic, :user => user }
66
let(:user) { Factory :user }
77
let(:newbie) { Factory :newbie }
8+
let(:admin) { Factory :admin }
89

910
describe ":index" do
1011
it "should have an index action" do
@@ -56,7 +57,7 @@
5657
get :new
5758
response.should be_success
5859
end
59-
60+
6061
it "should not allow access from newbie user" do
6162
sign_in newbie
6263
get :new
@@ -120,4 +121,35 @@
120121
end
121122
end
122123

124+
describe "#suggest" do
125+
it "should not allow user suggest" do
126+
sign_in user
127+
put :suggest, :id => topic
128+
topic.reload.excellent.should == 0
129+
end
130+
131+
it "should not allow user suggest by admin" do
132+
sign_in admin
133+
put :suggest, :id => topic
134+
topic.reload.excellent.should == 1
135+
end
136+
end
137+
138+
describe "#unsuggest" do
139+
context "suggested topic" do
140+
let!(:topic) { FactoryGirl.create(:topic, :excellent => 1) }
141+
142+
it "should not allow user suggest" do
143+
sign_in user
144+
put :unsuggest, :id => topic
145+
topic.reload.excellent.should == 1
146+
end
147+
148+
it "should not allow user suggest by admin" do
149+
sign_in admin
150+
put :unsuggest, :id => topic
151+
topic.reload.excellent.should == 0
152+
end
153+
end
154+
end
123155
end

0 commit comments

Comments
 (0)