Skip to content

Commit

Permalink
Merge branch 'supporter_level_goal' into update-react-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
wwahammy authored Nov 7, 2023
2 parents cde9f06 + 70dab30 commit 0087b13
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 38 deletions.
9 changes: 9 additions & 0 deletions app/models/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ def hide_cover_fees?
nonprofit.hide_cover_fees? || misc_campaign_info&.hide_cover_fees_option
end

def fee_coverage_option
@fee_coverage_option ||= misc_campaign_info&.fee_coverage_option_config || nonprofit.fee_coverage_option
end

# generally, don't use
def fee_coverage_option=(option)
@fee_coverage_option = option
end

def paused?
!!(misc_campaign_info&.paused)
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/misc_campaign_info.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
class MiscCampaignInfo < ApplicationRecord
belongs_to :campaign

validates_inclusion_of :fee_coverage_option_config, in: ['auto', 'manual', 'none', nil]

attr_accessible :manual_cover_fees, :paused
end
2 changes: 2 additions & 0 deletions app/models/miscellaneous_np_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ class MiscellaneousNpInfo < ApplicationRecord
:hide_cover_fees

belongs_to :nonprofit

validates_inclusion_of :fee_coverage_option_config, in: ['auto', 'manual', 'none', nil]
end
9 changes: 9 additions & 0 deletions app/models/nonprofit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ def hide_cover_fees?
miscellaneous_np_info&.hide_cover_fees
end

def fee_coverage_option
@fee_coverage_option ||= miscellaneous_np_info&.fee_coverage_option_config || 'auto'
end

# generally, don't use
def fee_coverage_option=(option)
@fee_coverage_option = option
end

concerning :PathCaching do
included do
after_save do
Expand Down
1 change: 0 additions & 1 deletion app/views/campaigns/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@
<% end %>

<%= render 'components/share_modal', name: @campaign.name, type: 'campaign' %>
<%= render 'common/email_share_modal', fundraiser: @campaign.name, fundraiser_url: @url %>
33 changes: 0 additions & 33 deletions app/views/common/_email_share_modal.html.erb

This file was deleted.

3 changes: 1 addition & 2 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,4 @@

<%= render 'nonprofits/donate/modal' %>
<%= render 'tickets/new_modal', profile: current_user ? current_user.profile : nil, hide_cover_fees_option: !!@event.hide_cover_fees? %>
<%= render 'contact_organizer_modal' %>
<%= render 'common/email_share_modal', fundraiser: @event.name, fundraiser_url: @url %>
<%= render 'contact_organizer_modal' %>
2 changes: 1 addition & 1 deletion app/views/nonprofits/_transaction_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Payouts
</a>
<a href='<%= nonprofits_recurring_donations_path(@nonprofit) %>'
class='<%= active == :recurring && 'is-active' %> lockedFeature'>
class='<%= active == :recurring && 'is-active' %>'>
Recurring
</a>
<a href='<%= nonprofits_charges_path(@nonprofit) %>'
Expand Down
1 change: 0 additions & 1 deletion app/views/nonprofits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@

<%= render 'components/share_modal', name: @nonprofit.name, type: 'nonprofit' %>
<%= render 'nonprofits/donate/modal' %>
<%= render 'common/email_share_modal', fundraiser: @nonprofit.name, fundraiser_url: @url %>

<%= render 'settings_modals' if current_nonprofit_user? %>

Expand Down
5 changes: 5 additions & 0 deletions spec/factories/misc_campaign_infos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
FactoryBot.define do
factory :misc_campaign_info do
end
end
30 changes: 30 additions & 0 deletions spec/models/campaign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,34 @@ def get_uploader_attribute_keys
end
end
end

describe '#fee_coverage_option' do
let(:campaign) {build(:campaign, nonprofit: nonprofit)}

let(:nonprofit) { build(:nonprofit, fee_coverage_option: 'manual')}

it 'is set to nonprofit.fee_coverage_option when misc_campaign_info is not there' do
expect(campaign.fee_coverage_option).to eq nonprofit.fee_coverage_option
end

it 'is set to nonprofit.fee_coverage_option when misc_campaign_info.fee_coverage_option_config is nil' do
campaign.misc_campaign_info = build(:misc_campaign_info, fee_coverage_option_config: nil)
expect(campaign.fee_coverage_option).to eq nonprofit.fee_coverage_option
end

it 'is set to manual when misc_campaign_info.fee_coverage_option_config is manual' do
campaign.misc_campaign_info = build(:misc_campaign_info, fee_coverage_option_config: 'manual')
expect(campaign.fee_coverage_option).to eq 'manual'
end

it 'is set to auto when misc_campaign_info.fee_coverage_option_config is auto' do
campaign.misc_campaign_info = build(:misc_campaign_info, fee_coverage_option_config: 'auto')
expect(campaign.fee_coverage_option).to eq 'auto'
end

it 'is set to none when misc np info fee_coverage_option_config is none' do
campaign.misc_campaign_info = build(:misc_campaign_info, fee_coverage_option_config: 'none')
expect(campaign.fee_coverage_option).to eq 'none'
end
end
end
8 changes: 8 additions & 0 deletions spec/models/misc_campaign_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'

RSpec.describe MiscCampaignInfo, :type => :model do
it {is_expected.to have_db_column(:fee_coverage_option_config).of_type(:string).with_options(null: true, default: nil) }

it {is_expected.to validate_inclusion_of(:fee_coverage_option_config).in_array(['auto', 'manual', 'none', nil])}
end
8 changes: 8 additions & 0 deletions spec/models/miscellaneous_np_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'

RSpec.describe MiscellaneousNpInfo, :type => :model do
it {is_expected.to have_db_column(:fee_coverage_option_config).of_type(:string).with_options(null: true, default: nil) }

it {is_expected.to validate_inclusion_of(:fee_coverage_option_config).in_array(['auto', 'manual', 'none', nil])}
end
28 changes: 28 additions & 0 deletions spec/models/nonprofit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@
end
end

describe '#fee_coverage_option' do
let(:nonprofit) {build(:nonprofit)}

it 'is set to auto when miscellaneous_np_info is missing' do
expect(nonprofit.fee_coverage_option).to eq 'auto'
end

it 'is set to auto when miscellaneous_np_info.fee_coverage_option_config is nil' do
nonprofit.miscellaneous_np_info = build(:miscellaneous_np_info, fee_coverage_option_config: nil)
expect(nonprofit.fee_coverage_option).to eq 'auto'
end

it 'is set to manual when miscellaneous_np_info.fee_coverage_option_config is manual' do
nonprofit.miscellaneous_np_info = build(:miscellaneous_np_info, fee_coverage_option_config: 'manual')
expect(nonprofit.fee_coverage_option).to eq 'manual'
end

it 'is set to auto when miscellaneous_np_info.fee_coverage_option_config is auto' do
nonprofit.miscellaneous_np_info = build(:miscellaneous_np_info, fee_coverage_option_config: 'auto')
expect(nonprofit.fee_coverage_option).to eq 'auto'
end

it 'is set to none when miscellaneous_np_info.fee_coverage_option_config is none' do
nonprofit.miscellaneous_np_info = build(:miscellaneous_np_info, fee_coverage_option_config: 'none')
expect(nonprofit.fee_coverage_option).to eq 'none'
end
end

describe '.currency_symbol' do

let(:nonprofit) {force_create(:nonprofit, currency: 'eur')}
Expand Down

0 comments on commit 0087b13

Please sign in to comment.