Sha256: c03a5f8f3b3038423ec7add098d44145a8d57029a55acae5cf2b4ec1eb3bd2ec

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

require "rails_helper"

RSpec.describe Tang::ApplicationHelper, :type => :helper do
  before { StripeMock.start }
  after { StripeMock.stop }

  describe "#created_datetime" do
    it "returns a formatted date" do
      created_at = Time.new(2015, 8, 1, 14, 35, 0)
      expect(helper.created_datetime(created_at)).to eq('2015/08/01 14:35')
    end
  end

  describe "#plan_cost" do
    it "returns a formatted cost" do
      plan = FactoryBot.build(:plan)
      expect(helper.plan_cost(plan)).to eq('$20.00/month')
    end
  end

  describe "#customer_plan_cost" do
    it "returns a formatted cost" do
      subscription = FactoryBot.build(:subscription)
      expect(helper.customer_plan_cost(subscription.customer, subscription.plan)).to eq('$20.00/month')
    end

    it "returns a percent off discounted formatted cost" do
      subscription = FactoryBot.build(:subscription)
      coupon = FactoryBot.build(:coupon)
      subscription.customer.coupon = coupon
      expect(helper.customer_plan_cost(subscription.customer, subscription.plan)).to eq('$10.00/month')
    end

    it "returns an amount off discounted formatted cost" do
      subscription = FactoryBot.build(:subscription)
      coupon = FactoryBot.build(:amount_off_coupon)
      subscription.customer.coupon = coupon
      expect(helper.customer_plan_cost(subscription.customer, subscription.plan)).to eq('$15.00/month')
    end
  end

  describe "#current_customer" do
    it "returns the current customer" do
      customer = FactoryBot.build(:customer)
      assign(:current_customer, customer)
      expect(helper.current_customer).to eq(customer)
    end
  end

  describe "#coupon_off" do
    it "returns a formatted percent off discount" do
      coupon = FactoryBot.build(:coupon)
      expect(helper.coupon_off(coupon)).to eq("50\% off")
    end

    it "returns a formatted amount off discount" do
      coupon = FactoryBot.build(:amount_off_coupon)
      expect(helper.coupon_off(coupon)).to eq('$5.00 off')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tang-0.2.1 spec/helpers/tang/application_helper_spec.rb
tang-0.2.0 spec/helpers/tang/application_helper_spec.rb
tang-0.1.0 spec/helpers/tang/application_helper_spec.rb
tang-0.0.9 spec/helpers/tang/application_helper_spec.rb
tang-0.0.8 spec/helpers/tang/application_helper_spec.rb