questions_spec.rb
6.93 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Questions" do
include IntegrationSupport
before do
3.times{ Factory.create(:aoi_question, :site => @api_user) }
end
describe "GET 'index'" do
it "should return an array of questions" do
get_auth questions_path(:format => 'xml')
response.body.should have_tag("questions question", 3)
response.should be_success
end
it "should not return the questions of other api users" do
pending ("doesn't scope to the level of the user") do
other_user = Factory(:email_confirmed_user)
Factory.create(:aoi_question, :site => other_user)
get_auth questions_path
response.should be_success
response.body.should_not have_tag("question")
end
end
end
describe "GET 'new'" do
it "should return an empty question object" do
get_auth new_question_path(:format => 'xml')
response.should be_success
response.body.should have_tag "question", 1
response.body.should have_tag "question name", ""
response.body.should have_tag "question creator-id", ""
response.body.should have_tag "question created-at", ""
end
end
describe "POST 'create'" do
before { @visitor = Factory.create(:visitor, :site => @api_user) }
it "should fail when required parameters are omitted" do
post_auth questions_path(:format => 'xml')
response.should_not be_success
end
it "should return a question object given no optional parameters" do
pending("choice count doesn't reflect # seed ideas") do
params = { :question => { :visitor_identifier => @visitor.identifier, :ideas => "foo\r\nbar\r\nbaz" } }
post_auth questions_path(:format => 'xml'), params
response.should be_success
response.should have_tag "question", 1
response.should have_tag "question creator-id", @visitor.id.to_s
response.should have_tag "question choices-count", 3
end
end
it "should correctly set optional attributes" do
params = {
:question => {
:visitor_identifier => @visitor.identifier,
:ideas => "foo\r\nbar\r\nbaz",
:name => "foo",
:local_identifier => "bar",
:information => "baz" } }
post_auth questions_path(:format => 'xml'), params
response.should be_success
response.should have_tag "question", 1
response.should have_tag "question creator-id", @visitor.id.to_s
# response.should have_tag "question choices-count", 3
response.should have_tag "question name", "foo"
response.should have_tag "question local-identifier", "bar"
response.should have_tag "question information", "baz"
end
end
describe "POST 'export'" do
before { @question = Factory.create(:aoi_question, :site => @api_user) }
it "should fail without any of the required parameters" do
post_auth export_question_path(@question, :format => 'xml')
response.should be_success
response.body.should =~ /Error/
end
it "should fail given invalid parameters" do
params = { :type => "ideas", :response_type => "foo", :redisk_key => "bar" }
post_auth export_question_path(@question, :format => 'xml')
response.should be_success
response.body.should =~ /Error/
end
it "should succeed given valid parameters" do
params = { :type => "ideas", :response_type => "redis", :redis_key => "foo" }
post_auth export_question_path(@question, :format => 'xml'), params
response.should be_success
response.body.should =~ /Ok!/
end
end
describe "GET 'show'" do
before { @question = Factory.create(:aoi_question, :site => @api_user) }
it "should succeed given no optional parameters" do
get_auth question_path(@question, :format => 'xml')
response.should be_success
response.should have_tag "question", 1
response.should have_tag "question id", @question.id.to_s
end
it "should correctly set optional parameters" do
@visitor = Factory.create(:visitor, :site => @api_user)
params = {
:visitor_identifier => @visitor.identifier,
:with_prompt => true,
:with_appearance => true,
:with_visitor_stats => true }
get_auth question_path(@question, :format => 'xml'), params
response.should be_success
response.should have_tag "question", 1
response.should have_tag "question id", @question.id.to_s
response.should have_tag "question picked_prompt_id"
response.should have_tag "question appearance_id"
response.should have_tag "question visitor_votes"
response.should have_tag "question visitor_ideas"
end
it "should fail if 'with_prompt' is set but 'visitor_identifier' not provided" do
pending("figure out argument dependencies") do
params = { :with_prompt => true }
get_auth question_path(@question, :format => 'xml'), params
response.should_not be_success
end
end
context "GET 'show' trying to view others sites' questions"
before do
@orig_user = @api_user
@api_user = Factory(:email_confirmed_user)
end
it "should fail" do
pending("user scope") do
get_auth question_path(@question, :format => 'xml')
response.should_not be_success
end
end
after { @api_user = @orig_user }
end
describe "PUT 'update'" do
before { @question = Factory.create(:aoi_question, :site => @api_user) }
it "should succeed give valid attributes" do
params = {
:question => {
:active => false,
:information => "foo",
:name => "bar",
:local_identifier => "baz" } }
put_auth question_path(@question, :format => 'xml'), params
response.should be_success
end
it "should not be able to change the site id" do
pending("needs attr_protected") do
original_site_id = @question.site_id
params = { :question => { :site_id => -1 } }
put_auth question_path(@question, :format => 'xml'), params
@question.reload.site_id.should == original_site_id
end
end
it "should ignore protected attributes" do
params = { :question => { :votes_count => 999 } }
put_auth question_path(@question, :format => 'xml'), params
response.should be_success
@question.reload.site_id.should_not == 999
end
context "when updatng another site's question" do
before do
@orig_user = @api_user
@api_user = Factory(:email_confirmed_user)
end
it "should fail" do
pending("user scope") do
params = { :question => { :name => "foo" } }
put_auth question_path(@question, :format => 'xml'), params
response.should_not be_success
end
end
after { @api_user = @orig_user }
end
end
describe "GET 'all_object_info_totals_by_date'" do
end
describe "GET 'object_info_totals_by_date'" do
end
end