-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcollections_controller_spec.rb
143 lines (119 loc) · 4.3 KB
/
collections_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'rails_helper'
describe CollectionsController, :type => :controller do
render_views
before(:each) do
Collection.destroy_all
end
describe "GET #show" do
it "NOT LOGGED IN should render" do
collection = create(:collection, :name => "Best collection eva")
get :show, :id => collection.to_param, :format => :html
expect(response).to be_success
expect(response.body).to match /Best collection eva/im
end
end
describe "GET #new" do
it "NOT LOGGED IN responds with a redirect" do
get :new, :format => :html
expect(response).to be_redirect
end
end
describe "GET #new" do
it "LOGGED IN responds with a success" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
get :new, :format => :html
expect(response).to be_success
end
end
describe "POST #create" do
it "LOGGED IN responds with success" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
collection_count = Collection.count
idea = create(:published_idea)
collection_params = {:name => "Boo ya collection", :ideas => {'0' => idea.sha}}
post :create, :collection => collection_params
expect(response).to be_redirect # as it's created the thing
expect(Collection.count).to eq(collection_count + 1)
end
end
describe "GET #show with JSON" do
it "should respond with JSON array" do
collection = create(:collection)
idea = create(:published_idea)
collection.ideas << idea
get :show, :id => collection.to_param, :format => :json
expect(response).to be_success
expect(response.status).to eq(200)
assert_equal hash_from_json(response.body)['ideas'].first["sha"], idea.sha
end
end
describe "GET #index with Atom" do
it "should respond with an Atom feed" do
collection = create(:collection)
idea = create(:published_idea)
collection.ideas << idea
get :show, :id => collection.to_param, :format => :atom
expect(response).to be_success
expect(response.status).to eq(200)
end
end
describe "GET #edit" do
it "NOT LOGGED IN responds with a redirect" do
collection = create(:collection)
get :edit, :id => collection.to_param, :format => :html
expect(response).to be_redirect
end
end
describe "GET #edit" do
it "LOGGED IN BUT NOT OWNER responds with a redirect" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
collection = create(:collection)
get :edit, :id => collection.to_param, :format => :html
expect(response).to be_redirect
end
end
describe "GET #edit" do
it "LOGGED IN BUT AS OWNER responds with success" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
collection = create(:collection, :user => user)
get :edit, :id => collection.to_param, :format => :html
expect(response).to be_success
end
end
describe "put #update" do
it "LOGGED IN BUT AS OWNER responds with success" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
collection = create(:collection, :user => user)
idea = create(:published_idea)
collection.ideas << idea
new_idea = create(:published_idea)
put :update, :id => collection.to_param, :collection => {:name => "Boo ya collection", :ideas => {'0' => new_idea.sha}}
expect(collection.ideas.count).to eq(1)
assert_equal collection.ideas.reload, [new_idea]
end
end
describe "delete" do
it "LOGGED IN AS OWNER should respond with success" do
user = create(:user)
allow(controller).to receive_message_chain(:current_user).and_return(user)
collection = create(:collection, :user => user)
collection_count = Collection.count
idea = create(:published_idea)
collection.ideas << idea
post :destroy, :id => collection.to_param
expect(Collection.count).to eq(collection_count - 1)
end
end
# Custom conference pages
describe "GET #dslhc" do
it "LOGGED OUT responds with a success" do
get :dslhc, :format => :html
expect(response).to be_success
end
end
end