prompts_spec.rb
6.41 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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
# to do: figure out future-prompts
# clean up repeated code
describe "Prompts" do
include IntegrationSupport
describe "GET 'show'" do
before do
@question = Factory.create(:aoi_question, :site => @api_user)
@prompt = @question.prompts.first
end
it "returns a prompt object" do
get_auth question_prompt_path(@question, @prompt, :format => 'xml')
response.should be_success
response.should have_tag "prompt", 1
end
end
describe "POST 'skip'" do
before do
@visitor = Factory.create(:visitor, :site => @api_user, :identifier => "foo")
@question = Factory.create(:aoi_question,
:site => @api_user,
:choices => [],
:prompts => [])
3.times{ Factory.create(:choice, :question => @question).activate! }
info = @question.reload.get_optional_information(:with_appearance => true,
:with_prompt => true,
:visitor_identifier => @visitor.identifier )
@appearance_id = info[:appearance_id]
@prompt_id = info[:picked_prompt_id]
end
it "should return a new skip object given no optional parameters" do
post_auth skip_question_prompt_path(@question.id, @prompt_id, :format => 'xml')
response.should be_success
response.should have_tag "skip", 1
end
it "should correctly set the optional attributes of the skip object" do
pending("shouldn\'t this set appearance_id?") do
params = {
:skip => {
:visitor_identifier => @visitor.identifier,
:skip_reason => "bar",
:appearance_lookup => @appearance_id,
:time_viewed => 47 } }
post_auth skip_question_prompt_path(@question, @prompt_id, :format => 'xml'), params
response.should be_success
response.should have_tag "skip", 1
response.should have_tag "skip appearance-id", @appearance_id.to_s
response.should have_tag "skip skip-reason", "bar"
response.should have_tag "skip time-viewed", "47"
response.should have_tag "skip skipper-id", @visitor.id.to_s
end
end
it "should return a prompt object if next_prompt is set" do
params = {
:next_prompt => {
:visitor_identifier => @visitor.identifier,
:with_appearance => true,
:algorithm => "catchup",
:with_visitor_stats => true } }
post_auth skip_question_prompt_path(@question, @prompt_id, :format => 'xml'), params
response.should be_success
response.should have_tag "prompt", 1
response.should have_tag "prompt appearance_id", /.+/
response.should have_tag "prompt visitor_votes", /\d+/
response.should have_tag "prompt visitor_ideas", /\d+/
end
context "when trying to skip another site's questions" do
before do
@orig_user = @api_user
@api_user = Factory(:email_confirmed_user)
end
it "should fail" do
post_auth skip_question_prompt_path(@question.id, @prompt_id, :format => 'xml')
response.should_not be_success
end
after { @api_user = @orig_user }
end
end
describe "POST 'vote'" do
before do
# dry this up
@visitor = Factory.create(:visitor, :site => @api_user, :identifier => "foo")
@question = Factory.create(:aoi_question,
:site => @api_user,
:choices => [],
:prompts => [])
3.times{ Factory.create(:choice, :question => @question).activate! }
info = @question.reload.get_optional_information(:with_appearance => true,
:with_prompt => true,
:visitor_identifier => @visitor.identifier )
@appearance_id = info[:appearance_id]
@prompt_id = info[:picked_prompt_id]
end
it "should fail without the required 'direction' parameter" do
post_auth vote_question_prompt_path(@question.id, @prompt_id, :format => 'xml')
response.should_not be_success
end
it "should return a new vote object given no optional parameters" do
params = { :vote => { :direction => "left" } }
post_auth vote_question_prompt_path(@question.id, @prompt_id, :format => 'xml'), params
response.should be_success
response.should have_tag "vote", 1
end
it "should correctly set the optional attributes of the vote object" do
pending("also has nil appearance id") do
params = {
:vote => {
:visitor_identifier => @visitor.identifier,
:direction => "right",
:appearance_lookup => @appearance_id,
:time_viewed => 47 } }
post_auth vote_question_prompt_path(@question, @prompt_id, :format => 'xml'), params
response.should be_success
response.should have_tag "vote", 1
response.should have_tag "vote appearance-id", @appearance_id.to_s
response.should have_tag "vote time-viewed", "47"
response.should have_tag "vote voter-id", @visitor.id.to_s
end
end
# copy-paste from vote --> shared behavior?
it "should return a prompt object if next_prompt is set" do
params = {
:vote => {
:direction => "left" },
:next_prompt => {
:visitor_identifier => @visitor.identifier,
:with_appearance => true,
:algorithm => "catchup",
:with_visitor_stats => true } }
post_auth vote_question_prompt_path(@question, @prompt_id, :format => 'xml'), params
response.should be_success
response.should have_tag "prompt", 1
response.should have_tag "prompt appearance_id", /.+/
response.should have_tag "prompt visitor_votes", /\d+/
response.should have_tag "prompt visitor_ideas", /\d+/
end
context "when trying to vote on another site's questions" do
before do
@orig_user = @api_user
@api_user = Factory(:email_confirmed_user)
end
it "should fail" do
params = { :vote => { :direction => "left" } }
post_auth vote_question_prompt_path(@question.id, @prompt_id, :format => 'xml'), params
response.should_not be_success
end
after { @api_user = @orig_user }
end
end
end