cirandas.net

ref: master

plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test_helper'

class ShoppingCartPluginTest < ActiveSupport::TestCase

  def setup
    @shopping_cart = ShoppingCartPlugin.new
    @context = mock()
    @profile = mock()
    @profile.stubs(:identifier).returns('random-user')
    @shopping_cart.context = @context
    @shopping_cart.stubs(:profile).returns(@profile)
  end

  attr_reader :shopping_cart
  attr_reader :context

  should 'return true to stylesheet' do
    assert shopping_cart.stylesheet?
  end

  should 'not add button if product unavailable' do
    profile = fast_create(:enterprise)
    product = fast_create(Product, :available => false, :profile_id => profile.id)
    profile.stubs(:shopping_cart).returns(true)

    assert_nil shopping_cart.add_to_cart_button(product)
  end

  should 'be disabled by default on the enterprise' do
    profile = fast_create(Enterprise)
    settings = profile.shopping_cart_settings
    assert !settings.enabled
  end
end