From fb2612ecaf8d390aa5d0f5cbf71507b36369bc4c Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 3 Sep 2018 21:28:14 +0200 Subject: [PATCH] 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. --- app/models/event.rb | 5 +---- app/models/registration.rb | 9 +-------- spec/models/registration_spec.rb | 18 ------------------ 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index 59a5d0b1..842dd970 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/models/registration.rb b/app/models/registration.rb index 66c33431..f7c032ea 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -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 diff --git a/spec/models/registration_spec.rb b/spec/models/registration_spec.rb index 417d90ff..ee3f0362 100644 --- a/spec/models/registration_spec.rb +++ b/spec/models/registration_spec.rb @@ -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