Refactor all has_enough_credits to enough_credits (#5119)

This commit is contained in:
Abner Soares Alves Junior 2019-12-16 12:00:59 -08:00 committed by Mac Siri
parent 1e34a2d8f9
commit 536c62da89
9 changed files with 15 additions and 15 deletions

View file

@ -92,7 +92,7 @@ class Organization < ApplicationRecord
ProfileImage.new(self).get(90)
end
def has_enough_credits?(num_credits_needed)
def enough_credits?(num_credits_needed)
credits.unspent.size >= num_credits_needed
end

View file

@ -447,7 +447,7 @@ class User < ApplicationRecord
currently_streaming_on == "twitch"
end
def has_enough_credits?(num_credits_needed)
def enough_credits?(num_credits_needed)
credits.unspent.size >= num_credits_needed
end

View file

@ -11,7 +11,7 @@ module Credits
end
def call
return false unless purchaser.has_enough_credits?(cost)
return false unless purchaser.enough_credits?(cost)
purchaser.credits.unspent.limit(cost).update_all(
spent: true,

View file

@ -12,7 +12,7 @@ module ProMemberships
user = membership.user
cost = ProMembership::MONTHLY_COST
if user.has_enough_credits?(cost)
if user.enough_credits?(cost)
renew_membership(membership, cost)
elsif membership.auto_recharge
if user.stripe_id_code

View file

@ -27,7 +27,7 @@ module ProMemberships
def purchase_pro_membership
cost = ProMembership::MONTHLY_COST
return false unless user.has_enough_credits?(cost)
return false unless user.enough_credits?(cost)
ActiveRecord::Base.transaction do
pro_membership = ProMembership.create!(user: user)

View file

@ -18,7 +18,7 @@ module ProMemberships
where("DATE(expires_at) = ?", expiration_date).
where(auto_recharge: false)
relation.find_each do |membership|
next if membership.user.has_enough_credits?(ProMembership::MONTHLY_COST)
next if membership.user.enough_credits?(ProMembership::MONTHLY_COST)
# NOTE: maybe we should "deliver_later" and update the flags there
ProMembershipMailer.expiring_membership(membership, expiration_date).deliver_now

View file

@ -12,7 +12,7 @@
</div>
<% elsif %w[silver bronze tag].include?(level) %>
<% organizations.find_each do |org| %>
<% if !org.has_enough_credits?(Sponsorship::CREDITS[level]) %>
<% if !org.enough_credits?(Sponsorship::CREDITS[level]) %>
<div class="partner-credits-explainer">
<h4>What next?</h4>
<h3><img src="<%= ProfileImage.new(org).get(90) %>" /> Purchase Credits for @<%= org.slug %></h3>

View file

@ -172,19 +172,19 @@ RSpec.describe Organization, type: :model do
end
end
describe "#has_enough_credits?" do
describe "#enough_credits?" do
it "returns false if the user has less unspent credits than neeed" do
expect(organization.has_enough_credits?(1)).to be(false)
expect(organization.enough_credits?(1)).to be(false)
end
it "returns true if the user has the exact amount of unspent credits" do
create(:credit, organization: organization, spent: false)
expect(organization.has_enough_credits?(1)).to be(true)
expect(organization.enough_credits?(1)).to be(true)
end
it "returns true if the user has more unspent credits than needed" do
create_list(:credit, 2, organization: organization, spent: false)
expect(organization.has_enough_credits?(1)).to be(true)
expect(organization.enough_credits?(1)).to be(true)
end
end

View file

@ -713,19 +713,19 @@ RSpec.describe User, type: :model do
end
end
describe "#has_enough_credits?" do
describe "#enough_credits?" do
it "returns false if the user has less unspent credits than neeed" do
expect(user.has_enough_credits?(1)).to be(false)
expect(user.enough_credits?(1)).to be(false)
end
it "returns true if the user has the exact amount of unspent credits" do
create(:credit, user: user, spent: false)
expect(user.has_enough_credits?(1)).to be(true)
expect(user.enough_credits?(1)).to be(true)
end
it "returns true if the user has more unspent credits than needed" do
create_list(:credit, 2, user: user, spent: false)
expect(user.has_enough_credits?(1)).to be(true)
expect(user.enough_credits?(1)).to be(true)
end
end
end