Commit 64564bbfdaf592863d19153a85f1d0fc372b0c26

Authored by Luke Baker
1 parent 7a1ca139

convert .rand calls to .sample

Showing 1 changed file with 19 additions and 19 deletions   Show diff stats
spec/integration/visitors_spec.rb
... ... @@ -6,7 +6,7 @@ describe "Visitors" do
6 6 before do
7 7 @user = self.default_user = Factory(:email_confirmed_user)
8 8 @visitors = @user.visitors << Array.new(30){ Factory(:visitor, :site => @user) }
9   - @questions = Array.new(3){ Factory(:aoi_question, :site => @user, :creator => @visitors.rand) }
  9 + @questions = Array.new(3){ Factory(:aoi_question, :site => @user, :creator => @visitors.sample) }
10 10 end
11 11  
12 12 describe "GET 'index'" do
... ... @@ -30,8 +30,8 @@ describe &quot;Visitors&quot; do
30 30 it "should return the number of votes for each visitor" do
31 31 counts = Hash.new(0)
32 32 20.times do
33   - visitor = @visitors.rand
34   - Factory(:vote, :question => @questions.rand, :voter => visitor)
  33 + visitor = @visitors.sample
  34 + Factory(:vote, :question => @questions.sample, :voter => visitor)
35 35 counts[visitor.id] += 1
36 36 end
37 37 get_auth visitors_path, :votes_count => true
... ... @@ -49,8 +49,8 @@ describe &quot;Visitors&quot; do
49 49 it "should return the number of skips for each visitor" do
50 50 counts = Hash.new(0)
51 51 20.times do
52   - visitor = @visitors.rand
53   - Factory(:skip, :question => @questions.rand, :skipper => visitor)
  52 + visitor = @visitors.sample
  53 + Factory(:skip, :question => @questions.sample, :skipper => visitor)
54 54 counts[visitor.id] += 1
55 55 end
56 56 get_auth visitors_path, :skips_count => true
... ... @@ -67,14 +67,14 @@ describe &quot;Visitors&quot; do
67 67  
68 68 it "should return the number of user-submitted choices" do
69 69 10.times do
70   - question = @questions.rand
  70 + question = @questions.sample
71 71 creator = question.creator
72 72 Factory(:choice, :question => question, :creator => creator)
73 73 end
74 74 counts = Hash.new(0)
75 75 10.times do
76   - question = @questions.rand
77   - creator = (@visitors - [question.creator]).rand
  76 + question = @questions.sample
  77 + creator = (@visitors - [question.creator]).sample
78 78 counts[creator.id] += 1
79 79 Factory(:choice, :question => question, :creator => creator)
80 80 end
... ... @@ -93,12 +93,12 @@ describe &quot;Visitors&quot; do
93 93 it "should show which visitors are bounces" do
94 94 bounce = {}
95 95 @visitors.each do |v|
96   - if [true,false].rand
97   - Factory(:appearance, :question => @questions.rand, :voter => v)
  96 + if [true,false].sample
  97 + Factory(:appearance, :question => @questions.sample, :voter => v)
98 98 bounce[v.id] = 1
99 99 else
100   - vote = Factory(:vote, :question => @questions.rand, :voter => v)
101   - Factory(:appearance, :question => @questions.rand,
  100 + vote = Factory(:vote, :question => @questions.sample, :voter => v)
  101 + Factory(:appearance, :question => @questions.sample,
102 102 :voter => v, :answerable => vote)
103 103 end
104 104 end
... ... @@ -134,10 +134,10 @@ describe &quot;Visitors&quot; do
134 134  
135 135 it "should return the visitor counts for a single question" do
136 136 votes, skips, choices = Array.new(3){ Hash.new(0) }
137   - the_question = @questions.rand
  137 + the_question = @questions.sample
138 138 20.times do
139   - question = @questions.rand
140   - visitor = (@visitors - [question.creator]).rand
  139 + question = @questions.sample
  140 + visitor = (@visitors - [question.creator]).sample
141 141 case rand(3)
142 142 when 0 then
143 143 Factory(:vote, :question => question, :voter => visitor)
... ... @@ -172,15 +172,15 @@ describe &quot;Visitors&quot; do
172 172 end
173 173  
174 174 it "should return the bounces for a single question" do
175   - the_question = @questions.rand
  175 + the_question = @questions.sample
176 176 bounces = @visitors.inject({}) do |h,v|
177 177 if v.id.odd? # bounce!
178   - question = @questions.rand
  178 + question = @questions.sample
179 179 Factory(:appearance, :question => question, :voter => v)
180 180 h[v.id] = 1 if question == the_question
181 181 else # appearance w/ answerable
182   - vote = Factory(:vote, :question => @questions.rand, :voter => v)
183   - Factory(:appearance, :question => @questions.rand, :voter => v, :answerable => vote)
  182 + vote = Factory(:vote, :question => @questions.sample, :voter => v)
  183 + Factory(:appearance, :question => @questions.sample, :voter => v, :answerable => vote)
184 184 end
185 185 h
186 186 end
... ...