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
|
.distinct
|
||||||
.pluck(:created_at)
|
.pluck(:created_at)
|
||||||
frequency = (last_datetimes.map(&:to_time).map(&:to_i).sum / (num_orders * 10))
|
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.frecency = frequency * bonus
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def rich_privilige
|
def rich_privilege
|
||||||
Math.atan(self.balance / 10) + (Math::PI / 2)
|
Math.atan(self.balance / 10) + (Math::PI / 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -150,15 +150,7 @@ describe User do
|
||||||
expect(@user.frecency).to_not eq 0
|
expect(@user.frecency).to_not eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be valid' do
|
# TODO: add a test to check if the frecency is correct. Note that
|
||||||
dates = [Date.today.to_time, Date.yesterday.to_time]
|
# frecency currently changes over 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue