forked from rughh/on_ruby
/
events_controller_spec.rb
55 lines (40 loc) · 1.27 KB
/
events_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'
describe EventsController do
let(:event) { Factory(:event) }
let(:user) { Factory(:user) }
describe "GET :rss" do
before { get :rss, format: :xml }
it "should assign the events to display" do
controller.events.should_not be_nil
end
it "should render the :rss template" do
response.should render_template(:rss)
end
end
describe "GET :show" do
before do
get :show, id: event.id
end
it "should assign the requested event" do
controller.event.should eql(event)
end
it "should render the :show template" do
response.should render_template(:show)
end
end
describe "POST :add_user" do
it "should add a prticipant for current user" do
controller.stubs(current_user: user)
expect { post :add_user, id: event.id }.to change(Participant, :count).by(1)
flash[:notice].should_not be_nil
response.should redirect_to(event)
end
it "should should not add paritcipant if already exists" do
user.participants.create(event: event)
controller.stubs(current_user: user)
expect { post :add_user, id: event.id }.to change(Participant, :count).by(0)
flash[:alert].should_not be_nil
response.should redirect_to(event)
end
end
end