Removed non-deterministic test, corrected typo
This commit is contained in:
parent
05c83fb5cc
commit
2e3ee95de8
2 changed files with 5 additions and 13 deletions
|
@ -47,12 +47,12 @@ class User < ActiveRecord::Base
|
|||
.distinct
|
||||
.pluck(:created_at)
|
||||
frequency = (last_datetimes.map(&:to_time).map(&:to_i).sum / (num_orders * 10))
|
||||
bonus = self.rich_privilige / 1.936
|
||||
bonus = self.rich_privilege / 1.936
|
||||
self.frecency = frequency * bonus
|
||||
self.save
|
||||
end
|
||||
|
||||
def rich_privilige
|
||||
def rich_privilege
|
||||
Math.atan(self.balance / 10) + (Math::PI / 2)
|
||||
end
|
||||
|
||||
|
|
|
@ -144,21 +144,13 @@ describe User do
|
|||
end
|
||||
|
||||
it 'should be recalculated on creating an order' do
|
||||
|
||||
|
||||
expect(@user.frecency).to eq 0
|
||||
create :order, user: @user
|
||||
expect(@user.frecency).to_not eq 0
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
dates = [Date.today.to_time, Date.yesterday.to_time]
|
||||
dates.each do |date|
|
||||
create :order, user: @user, created_at: date
|
||||
end
|
||||
@user.reload
|
||||
num_orders = Rails.application.config.frecency_num_orders
|
||||
# On Travis the result is 10025938 cause floating points
|
||||
expect(@user.frecency).to be_within(50).of(10025915)
|
||||
end
|
||||
# TODO: add a test to check if the frecency is correct. Note that
|
||||
# frecency currently changes over time
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue