* feat: remove initializeSponsorshipVisibility and related code * feat: remove sponsorships from sidebar * feat: remove sponsorships from the admin - route, controller, view, spec * feat: remove the admin menu item * feat: remove the i8n for admin sponsors controller * feat: sponsorship decorator was not being used anywhere * feat: sponsorship slack messenger was not being used anywhere * feat: remove the sponsorship_headline that gets configures on the admin * feat: remove the /sponsors page * feat: remove renedring of single_sponsor partial and associated partials * feat: remove the navigation link rake task for sponsors * feat: remove sponsorship from tags * feat: remove i8n constants used * remove sponsor references in text to the privacy page * feat: remove the sponsorship detail from the organization page * feat: remove the sponsors css that was used for app/views/pages/sponsors.html.erb * feat: remove the sponsorship i8n that was used in the slack messengers * feat: swap out the decorators to use Article as an example * feat: remove spec to show sponsors on home page * feat: update the specs to use Article Decorator instead of the Sponsorship Decorator * fix: use direct and not all * fix: remove tests for tag sponsorship * fix: remove organization sponsorship test * feat: remove more i8n * remove unused css from app/views/organizations/_sidebar_additional.html.erb * feat: remove sponsorship relationship from tag and organization * remove seed * feat: remove all Sponsor related specs * feat: remove model, associated i8n and specs * feat: remove sponsor from navbar * feat: add a guard clause if we're unable to constantinize the purchase_type * feat; remove sponsorship related tests * feat: remove sponsorship relationship * feat: remov especs related to sponsorship * feat: remove tag sponsorship validation * feat: remove the sponsorship factory
49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Credits::Ledger, type: :service do
|
|
let(:user) { create(:user) }
|
|
let(:org) { create(:organization) }
|
|
let(:user_listing) { create(:listing, user: user) }
|
|
let(:org_listing) { create(:listing, organization: org) }
|
|
|
|
def buy(purchaser, purchase, cost)
|
|
params = {
|
|
spent: true,
|
|
spent_at: Time.current,
|
|
purchase_type: purchase.class.name,
|
|
purchase_id: purchase.id
|
|
}
|
|
params.merge!((
|
|
purchaser.is_a?(User) ? { user: purchaser } : { organization: purchaser }))
|
|
create_list(:credit, cost, params)
|
|
end
|
|
|
|
it "returns a list of user purchases with their costs" do
|
|
Timecop.freeze(Time.current) do
|
|
start = Time.current
|
|
buy(user, user_listing, 3)
|
|
|
|
items = described_class.call(user)[[User.name, user.id]]
|
|
expect(items.length).to be(1)
|
|
|
|
item = items.first
|
|
expect(item.purchase.is_a?(Listing)).to be(true)
|
|
expect(item.cost).to eq(3)
|
|
expect(item.purchased_at.to_i >= start.to_i).to be(true)
|
|
end
|
|
end
|
|
|
|
it "returns a list of purchases for the org the user is an admin for" do
|
|
create(:organization_membership, user_id: user.id, organization_id: org.id, type_of_user: "admin")
|
|
buy(org, org_listing, 3)
|
|
items = described_class.call(user)[[Organization.name, org.id]]
|
|
expect(items.length).to be(1)
|
|
end
|
|
|
|
it "does not return purchases for other orgs the user belongs to" do
|
|
create(:organization_membership, user_id: user.id, organization_id: org.id, type_of_user: "member")
|
|
buy(org, org_listing, 3)
|
|
items = described_class.call(user)[[Organization.name, org.id]]
|
|
expect(items).to be_nil
|
|
end
|
|
end
|