-
- Credits will be allotted flexibly use in <%= community_name %>-produced podcasts, videos and other media content. You will be notified as it is being distributed.
-
-
- <% end %>
- <%# NOTE: this currently can't be reached %>
- <% elsif level == "devrel" %>
-
@<%= org.slug %>
-
This organization account has <%= org.credits.unspent.size %> credits available
<% if params[:option] == "gold-sponsor" %>
<%= render "gold_sponsor_copy" %>
diff --git a/spec/models/sponsorship_spec.rb b/spec/models/sponsorship_spec.rb
index d49ee65db..814cf2038 100644
--- a/spec/models/sponsorship_spec.rb
+++ b/spec/models/sponsorship_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe Sponsorship, type: :model do
describe "constants" do
it "has the correct values for constants" do
expect(Sponsorship::LEVELS).to eq(%w[gold silver bronze tag media devrel])
- expect(Sponsorship::LEVELS_WITH_EXPIRATION).to eq(%w[gold silver bronze])
+ expect(Sponsorship::METAL_LEVELS).to eq(%w[gold silver bronze])
expect(Sponsorship::STATUSES).to eq(%w[none pending live])
expected_credits = { gold: 6000, silver: 500, bronze: 100, tag: 300, devrel: 500 }.with_indifferent_access
expect(Sponsorship::CREDITS).to eq(expected_credits)
diff --git a/spec/requests/partnerships_spec.rb b/spec/requests/partnerships_spec.rb
index 815b525a8..972ff8d9a 100644
--- a/spec/requests/partnerships_spec.rb
+++ b/spec/requests/partnerships_spec.rb
@@ -126,7 +126,7 @@ RSpec.describe "Partnerships", type: :request do
let(:user) { create(:user) }
let(:org) { create(:organization) }
- context "when user is logged in as an admin and has enough credits" do
+ context "when user is logged in as an admin" do
before do
create(:organization_membership, user: user, organization: org, type_of_user: "admin")
sign_in user
@@ -135,7 +135,7 @@ RSpec.describe "Partnerships", type: :request do
# context "when purchasing a gold sponsorship" is skipped due
# to the high amount of required credits
- context "when purchasing a silver sponsorship" do
+ context "when purchasing a silver sponsorship and has enough credits" do
let(:params) { { level: :silver, organization_id: org.id } }
before do
@@ -179,129 +179,88 @@ RSpec.describe "Partnerships", type: :request do
context "when purchasing a bronze sponsorship" do
let(:params) { { level: :bronze, organization_id: org.id } }
- before do
- Credit.add_to(org, Sponsorship::CREDITS[:bronze])
- end
+ context "when enough credits" do
+ before do
+ Credit.add_to(org, Sponsorship::CREDITS[:bronze])
+ end
- it "creates a new sponsorship" do
- expect do
- post partnerships_path, params: params
- expect(response).to redirect_to(partnerships_path)
- end.to change(org.sponsorships, :count).by(1)
- end
+ it "creates a new sponsorship" do
+ expect do
+ post partnerships_path, params: params
+ expect(response).to redirect_to(partnerships_path)
+ end.to change(org.sponsorships, :count).by(1)
+ end
- it "subscribes with the correct info" do
- Timecop.freeze(Time.current) do
+ it "creates a flash notice" do
post partnerships_path, params: params
- sponsorship = org.sponsorships.bronze.last
- expect(sponsorship.status).to eq("pending")
- expect(sponsorship.expires_at.to_i).to eq(1.month.from_now.to_i)
- expect(sponsorship.sponsorable).to be(nil)
- expect(sponsorship.instructions).to be_blank
- expect(sponsorship.instructions_updated_at).to be(nil)
+ expect(flash[:notice]).to eq("You purchased a sponsorship")
+ end
+
+ it "subscribes with the correct info" do
+ Timecop.freeze(Time.current) do
+ post partnerships_path, params: params
+ sponsorship = org.sponsorships.bronze.last
+ expect(sponsorship.status).to eq("pending")
+ expect(sponsorship.expires_at.to_i).to eq(1.month.from_now.to_i)
+ expect(sponsorship.sponsorable).to be(nil)
+ expect(sponsorship.instructions).to be_blank
+ expect(sponsorship.instructions_updated_at).to be(nil)
+ end
+ end
+
+ it "detracts the correct amount of credits" do
+ expect do
+ post partnerships_path, params: params
+ end.to change(org.credits.spent, :size).by(Sponsorship::CREDITS[:bronze])
+ credit = org.credits.spent.last
+ expect(credit.purchase.is_a?(Sponsorship)).to be(true)
+ end
+
+ it "queues a slack message to be sent" do
+ sidekiq_assert_enqueued_with(job: Slack::Messengers::Worker) do
+ post partnerships_path, params: params
+ end
end
end
- it "detracts the correct amount of credits" do
- expect do
- post partnerships_path, params: params
- end.to change(org.credits.spent, :size).by(Sponsorship::CREDITS[:bronze])
- credit = org.credits.spent.last
- expect(credit.purchase.is_a?(Sponsorship)).to be(true)
- end
+ context "when not enough credits" do
+ it "doesn't create a new sponsorship" do
+ expect do
+ post partnerships_path, params: params
+ end.not_to change(org.sponsorships, :count)
+ end
- it "queues a slack message to be sent" do
- sidekiq_assert_enqueued_with(job: Slack::Messengers::Worker) do
+ it "redirects with a flash notice" do
post partnerships_path, params: params
+ expect(response).to redirect_to(partnerships_path)
+ expect(flash[:error]).to eq("Not enough credits")
end
end
end
- context "when purchasing a devrel sponsorship" do
- let(:params) { { level: :devrel, organization_id: org.id } }
+ %i[media devrel].each do |level|
+ context "when purchasing a #{level} sponsorship" do
+ let(:params) { { level: level, organization_id: org.id } }
- before do
- Credit.add_to(org, Sponsorship::CREDITS[:devrel])
- end
+ before do
+ Credit.add_to(org, Sponsorship::CREDITS[level].to_i)
+ end
- it "creates a new sponsorship" do
- expect do
+ it "doesn't create a Sponsorship" do
+ expect do
+ post partnerships_path, params: params
+ end.not_to change(Sponsorship, :count)
+ end
+
+ it "redirects with a notice" do
post partnerships_path, params: params
expect(response).to redirect_to(partnerships_path)
- end.to change(org.sponsorships, :count).by(1)
- end
-
- it "subscribes with the correct info" do
- Timecop.freeze(Time.current) do
- post partnerships_path, params: params
- sponsorship = org.sponsorships.devrel.last
- expect(sponsorship.status).to eq("pending")
- expect(sponsorship.expires_at).to be(nil)
- expect(sponsorship.sponsorable).to be(nil)
- expect(sponsorship.instructions).to be_blank
- expect(sponsorship.instructions_updated_at).to be(nil)
- end
- end
-
- it "detracts the correct amount of credits" do
- expect do
- post partnerships_path, params: params
- end.to change(org.credits.spent, :size).by(Sponsorship::CREDITS[:devrel])
- credit = org.credits.spent.last
- expect(credit.purchase.is_a?(Sponsorship)).to be(true)
- end
-
- it "queues a slack message to be sent" do
- sidekiq_assert_enqueued_with(job: Slack::Messengers::Worker) do
- post partnerships_path, params: params
+ expect(flash[:error]).to eq("#{level.capitalize} sponsorship is not a self-serving one")
end
end
end
- context "when purchasing a media sponsorship" do
- let(:params) do
- { level: :media, organization_id: org.id, amount: 10 }
- end
-
- before do
- Credit.add_to(org, params[:amount])
- end
-
- it "creates a new sponsorship" do
- expect do
- post partnerships_path, params: params
- expect(response).to redirect_to(partnerships_path)
- end.to change(org.sponsorships, :count).by(1)
- end
-
- it "subscribes with the correct info" do
- Timecop.freeze(Time.current) do
- post partnerships_path, params: params
- sponsorship = org.sponsorships.media.last
- expect(sponsorship.status).to eq("pending")
- expect(sponsorship.expires_at).to be(nil)
- expect(sponsorship.sponsorable).to be(nil)
- expect(sponsorship.instructions).to be_blank
- expect(sponsorship.instructions_updated_at).to be(nil)
- end
- end
-
- it "detracts the correct amount of credits" do
- expect do
- post partnerships_path, params: params
- end.to change(org.credits.spent, :size).by(params[:amount])
- credit = org.credits.spent.last
- expect(credit.purchase.is_a?(Sponsorship)).to be(true)
- end
-
- it "queues a slack message to be sent" do
- sidekiq_assert_enqueued_with(job: Slack::Messengers::Worker) do
- post partnerships_path, params: params
- end
- end
- end
-
- context "when purchasing a tag sponsorship" do
+ context "when purchasing a tag sponsorship and has enough credits" do
let(:tag) { create(:tag) }
let(:params) { { level: :tag, organization_id: org.id, tag_name: tag.name } }