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