Simplify set_week callbacks

Changes to :week are already ignored py paper_trail. No need to wrap this in a
`without_versioning`. Also drop the reader in `Registration` and the tests. Why
write this into the DB but never read it again? Why test standard
ruby/activerecord stuff.
This commit is contained in:
Henne Vogelsang 2018-09-03 21:28:14 +02:00
parent f458736a39
commit fb2612ecaf
3 changed files with 2 additions and 30 deletions

View file

@ -317,10 +317,7 @@ class Event < ApplicationRecord
end
def set_week
self.week = created_at.strftime('%W')
paper_trail.without_versioning do
save!
end
update!(week: created_at.strftime('%W'))
end
def before_end_of_conference

View file

@ -46,10 +46,6 @@ class Registration < ApplicationRecord
(conference.program.events.with_registration_open - events) + events
end
def week
created_at.strftime('%W').to_i
end
private
##
@ -76,10 +72,7 @@ class Registration < ApplicationRecord
end
def set_week
self.week = created_at.strftime('%W')
paper_trail.without_versioning do
save!
end
update!(week: created_at.strftime('%W'))
end
def registration_limit_not_exceed

View file

@ -40,16 +40,6 @@ describe 'Registration' do
describe 'after create' do
after { subject.run_callbacks(:create) }
# set_week and subscribe_to_conference are private methods
describe '#set_week' do
before { subject.created_at = Time.utc(2014, 5, 10) }
it 'sets week of registration' do
expect(subject).to receive(:set_week)
expect(subject.week).to eq 18
end
end
describe '#subscribe_to_conference' do
it 'subscribes to conference' do
expect(subject).to receive(:subscribe_to_conference)
@ -62,14 +52,6 @@ describe 'Registration' do
end
end
describe '#week' do
before { subject.created_at = Date.new(2014, 06, 30) }
it 'returns week number of created_at' do
expect(subject.week).to eq(26)
end
end
describe 'registration_to_events_only_if_present' do
context 'valid' do
it 'when user registers for events happening while user is at the conference' do