Skip to content

Commit

Permalink
use Durations for membership term, grace period; db = ISO string repr…
Browse files Browse the repository at this point in the history
…esentation
  • Loading branch information
weedySeaDragon committed Apr 5, 2021
1 parent cefc380 commit 2a2f196
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 60 deletions.
5 changes: 3 additions & 2 deletions app/controllers/admin_only/app_configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def app_config_params
:twitter_card_type,
:facebook_app_id,
:site_meta_image,
:membership_expired_grace_period_duration,
:membership_term_duration,
:payment_too_soon_days,
:membership_guideline_list_id,
:membership_expired_grace_period)
:membership_guideline_list_id)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def self.for_user_starting_on_or_after(user, first_day = Date.current)
where(user: user).starting_on_or_after(first_day)
end

# @return [ActiveSupport::Duration]
# @return [ActiveSupport::Duration] - the membership term length as a Duration. Must use a duration so we can handle leap years.
def self.term_length
AdminOnly::AppConfiguration.config_to_use.membership_term_length.to_i.days
ActiveSupport::Duration.parse(AdminOnly::AppConfiguration.config_to_use.membership_term_duration)
end


Expand Down
2 changes: 1 addition & 1 deletion app/models/memberships_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.days_can_renew_early

# @return [Duration] - the number of days after the end of a membership that a user can renew
def self.grace_period
AdminOnly::AppConfiguration.config_to_use.membership_expired_grace_period.to_i.days
ActiveSupport::Duration.parse(AdminOnly::AppConfiguration.config_to_use.membership_expired_grace_period_duration)
end


Expand Down
2 changes: 1 addition & 1 deletion app/models/reqs_updaters/requirements_for_renewal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def self.doc_uploaded_during_this_membership_term?(user)
end

def self.max_days_can_still_renew
AdminOnly::AppConfiguration.config_to_use.membership_expired_grace_period
ActiveSupport::Duration.parse(AdminOnly::AppConfiguration.config_to_use.membership_expired_grace_period_duration).days
end
end
18 changes: 0 additions & 18 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,6 @@ def membership_past_grace_period_end?(this_date = Date.current)
memberships_manager.date_after_grace_period_end?(self, this_date)
end

# FIXME: MembershipManager membership_expired_in_grace_period? means this is no longer used
# def date_within_grace_period?(this_date = Date.current,
# start_date = membership_expire_date,
# grace_period = membership_expired_grace_period)
# memberships_manager.date_in_grace_period?(this_date,
# last_day: start_date,
# grace_days: grace_period )
# end
#
# def membership_expired_grace_period
# memberships_manager.grace_period
# end

# @return [ActiveSupport::Duration]
# def days_can_renew_early
# memberships_manager.days_can_renew_early
# end


# @return [Symbol] - the membership status.
# If the membership status is current AND the given Date
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin_only/app_configuration/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
.form-row
.col-sm-12.membership-expired-grace-period
.form-inline
= f.label :membership_expired_grace_period, "#{t('.membership_expired_grace_period')}:", class: 'control-label field-label'
= f.number_field :membership_expired_grace_period, class: 'form-control membership-expired-grace-period', min: 0
= f.label :membership_expired_grace_period_duration, "#{t('.membership_expired_grace_period')}:", class: 'control-label field-label'
= f.number_field :membership_expired_grace_period_duration, class: 'form-control membership-expired-grace-period', min: 0

%hr
.row
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin_only/app_configuration/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
.row
.col-sm-10
= field_or_none(t('.membership_expired_grace_period'),
@app_configuration.membership_expired_grace_period,
@app_configuration.membership_expired_grace_period_duration,
tag_options: {class: 'membership-expired-grace-period'})

%hr
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddMembershipExpiredGracePeriodDurationToAppConfiguration < ActiveRecord::Migration[5.2]
def change

add_column :app_configurations, :membership_expired_grace_period_duration, :string, default: 'P90D', null: false, comment: "Duration after membership expiration that a member can pay without penalty. ISO 8601 Duration string format. Must be used so we can handle leap years"
end
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddMembershipTermDurationToAppConfiguration < ActiveRecord::Migration[5.2]
def change
add_column :app_configurations, :membership_term_duration, :string, default: 'P1Y', null: false, comment: "ISO 8601 Duration string format. Must be used so we can handle leap years. default = 1 year"
end
end

This file was deleted.

4 changes: 2 additions & 2 deletions db/seeders/app_configuration_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def self.seed_app_config
app_config.email_admin_new_app_received_enabled = true

app_config.payment_too_soon_days = 60
app_config.membership_expired_grace_period = (365 * 2)
app_config.membership_term_length = 365
app_config.membership_expired_grace_period_duration = 'P2Y' # 2 years
app_config.membership_term_duration ='P1Y' # 1 year
app_config.membership_expiring_soon_days = 31

membership_guideline_list_root = AdminOnly::MasterChecklist.find_by(displayed_text: 'Medlemsåtagande')
Expand Down
14 changes: 7 additions & 7 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ CREATE TABLE public.app_configurations (
site_meta_image_height integer DEFAULT 0 NOT NULL,
og_type character varying DEFAULT 'website'::character varying NOT NULL,
twitter_card_type character varying DEFAULT 'summary'::character varying NOT NULL,
facebook_app_id bigint DEFAULT '1292810030791186'::bigint NOT NULL,
facebook_app_id bigint DEFAULT '12345678909876'::bigint NOT NULL,
site_meta_image_file_name character varying,
site_meta_image_content_type character varying,
site_meta_image_file_size bigint,
site_meta_image_updated_at timestamp without time zone,
singleton_guard integer DEFAULT 0 NOT NULL,
payment_too_soon_days integer DEFAULT 60 NOT NULL,
membership_guideline_list_id bigint,
membership_expired_grace_period integer DEFAULT 90 NOT NULL,
membership_term_length integer DEFAULT 365 NOT NULL,
membership_expired_grace_period_duration character varying DEFAULT 'P90D'::character varying NOT NULL,
membership_term_duration character varying DEFAULT 'P1Y'::character varying NOT NULL,
membership_expiring_soon_days integer DEFAULT 60 NOT NULL
);

Expand All @@ -124,17 +124,17 @@ COMMENT ON COLUMN public.app_configurations.payment_too_soon_days IS 'Warn user


--
-- Name: COLUMN app_configurations.membership_expired_grace_period; Type: COMMENT; Schema: public; Owner: -
-- Name: COLUMN app_configurations.membership_expired_grace_period_duration; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public.app_configurations.membership_expired_grace_period IS 'Number of days after membership expiration that a member can pay without penalty';
COMMENT ON COLUMN public.app_configurations.membership_expired_grace_period_duration IS 'Duration after membership expiration that a member can pay without penalty. ISO 8601 Duration string format. Must be used so we can handle leap years';


--
-- Name: COLUMN app_configurations.membership_term_length; Type: COMMENT; Schema: public; Owner: -
-- Name: COLUMN app_configurations.membership_term_duration; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public.app_configurations.membership_term_length IS 'Number of days for a membership term';
COMMENT ON COLUMN public.app_configurations.membership_term_duration IS 'ISO 8601 Duration string format. Must be used so we can handle leap years. default = 1 year';


--
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/app_configuration_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@
end

And("the grace period is {digits} days") do |grace_period_days|
AdminOnly::AppConfiguration.config_to_use.update_attribute(:membership_expired_grace_period, grace_period_days)
AdminOnly::AppConfiguration.config_to_use.update_attribute(:membership_expired_grace_period_duration, "P#{grace_period_days}D")
end
2 changes: 1 addition & 1 deletion spec/models/admin_only/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
it { is_expected.to have_db_column :site_meta_image_width }
it { is_expected.to have_db_column :singleton_guard }
it { is_expected.to have_db_column :payment_too_soon_days }
it { is_expected.to have_db_column :membership_term_length }
it { is_expected.to have_db_column :membership_term_duration }
it { is_expected.to have_db_column :membership_expiring_soon_days }
end

Expand Down
6 changes: 3 additions & 3 deletions spec/models/membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def make_all_memberships


describe '.term_length' do
it 'gets the value from AppConfiguration' do
expect(AdminOnly::AppConfiguration.config_to_use).to receive(:membership_term_length)
.and_return(90)
it 'gets the duration string from AppConfiguration and turns it into a Duration' do
expect(AdminOnly::AppConfiguration.config_to_use).to receive(:membership_term_duration)
.and_return('P90D')
expect(described_class.term_length).to eq 90.days
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/memberships_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

describe '.grace_period' do
it 'gets the value from AppConfiguration and returns the number of days (Duration)' do
expect( AdminOnly::AppConfiguration.config_to_use).to receive(:membership_expired_grace_period)
.and_return(90)
expect( AdminOnly::AppConfiguration.config_to_use).to receive(:membership_expired_grace_period_duration)
.and_return('P90D')
expect(described_class.grace_period).to eq 90.days
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/reqs_updaters/requirements_for_renewal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@


describe '.max_days_can_still_renew' do
it 'gets the membership_expired_grace_period from the Application Configuration' do
expect(AdminOnly::AppConfiguration.config_to_use).to receive(:membership_expired_grace_period).and_return(5)
it 'gets the membership_expired_grace_period_duration from the Application Configuration and converts it to days' do
expect(AdminOnly::AppConfiguration.config_to_use).to receive(:membership_expired_grace_period_duration).and_return('P5D')
described_class.max_days_can_still_renew
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/shared_context/mock_app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def self.payment_too_soon_days
60
end

def self.membership_expired_grace_period
90
def self.membership_expired_grace_period_duration
'P90D'
end

def self.membership_term_length
365
def self.membership_term_duration
'P1Y'
end

def self.membership_expiring_soon_days
Expand Down

0 comments on commit 2a2f196

Please sign in to comment.