radiant-shop_discounts-extension 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  gem.email = "dk@dirkkelly.com"
8
8
  gem.homepage = "https://github.com/thefrontiergroup/radiant-shop_discounts-extension"
9
9
  gem.authors = ["Dirk Kelly"]
10
- gem.add_dependency 'radiant-shop-extension'
10
+ gem.add_dependency 'radiant-shop-extension', '0.92.2'
11
11
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
12
  end
13
13
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -35,6 +35,7 @@ class Admin::Shop::DiscountsController < Admin::ResourceController
35
35
  def config_edit
36
36
  @buttons << 'browse_categories'
37
37
  @buttons << 'browse_products'
38
+ @buttons << 'browse_users'
38
39
 
39
40
  @inputs << 'name'
40
41
  @inputs << 'amount'
@@ -45,9 +46,11 @@ class Admin::Shop::DiscountsController < Admin::ResourceController
45
46
 
46
47
  @parts << 'categories'
47
48
  @parts << 'products'
49
+ @parts << 'users'
48
50
 
49
51
  @popups << 'browse_categories'
50
52
  @popups << 'browse_products'
53
+ @popups << 'browse_users'
51
54
  end
52
55
 
53
56
  def assets_global
@@ -10,10 +10,12 @@ class ShopDiscount < ActiveRecord::Base
10
10
  belongs_to :updated_by, :class_name => 'User'
11
11
 
12
12
  has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discount_id
13
+
13
14
  has_many :categories, :through => :discountables, :source => :category, :conditions => "shop_discountables.discounted_type = 'ShopCategory'"
14
15
  has_many :products, :through => :discountables, :source => :product, :conditions => "shop_discountables.discounted_type = 'ShopProduct'"
15
16
  has_many :orders, :through => :discountables, :source => :order, :conditions => "shop_discountables.discounted_type = 'ShopOrder'"
16
17
  has_many :line_items, :through => :discountables, :source => :line_item,:conditions => "shop_discountables.discounted_type = 'ShopLineItem'"
18
+ has_many :users, :through => :discountables, :source => :user, :conditions => "shop_discountables.discounted_type = 'User'"
17
19
 
18
20
  validates_presence_of :name, :code, :amount
19
21
  validates_uniqueness_of :name, :code
@@ -34,4 +36,8 @@ class ShopDiscount < ActiveRecord::Base
34
36
  ShopProduct.all - products
35
37
  end
36
38
 
39
+ def available_users
40
+ User.all - users
41
+ end
42
+
37
43
  end
@@ -2,10 +2,12 @@ class ShopDiscountable < ActiveRecord::Base
2
2
 
3
3
  belongs_to :discount, :class_name => 'ShopDiscount', :foreign_key => :discount_id
4
4
  belongs_to :discounted, :foreign_key => :discounted_id, :polymorphic => true
5
+
5
6
  belongs_to :category, :class_name => 'ShopCategory', :foreign_key => :discounted_id
6
7
  belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :discounted_id
7
8
  belongs_to :order, :class_name => 'ShopOrder', :foreign_key => :discounted_id
8
9
  belongs_to :line_item, :class_name => 'ShopLineItem', :foreign_key => :discounted_id
10
+ belongs_to :user, :class_name => 'User', :foreign_key => :discounted_id
9
11
 
10
12
  validates_presence_of :discount, :discounted
11
13
  validates_uniqueness_of :discounted_id, :scope => [ :discount_id, :discounted_type ]
@@ -0,0 +1 @@
1
+ = link_to t('browse_users'), '#browse_users_popup', :class => 'popup button'
@@ -0,0 +1,3 @@
1
+ %ul#discount_users.users.discounteds
2
+ - @shop_discount.discountables.for('User').each do |user|
3
+ = render :partial => 'admin/shop/discounts/edit/shared/user', :locals => { :user => user }
@@ -0,0 +1,6 @@
1
+ %h3.title= t('browse_users')
2
+
3
+ %ul#available_users.availables
4
+ = render :partial => '/admin/shop/discounts/edit/shared/user', :collection => @shop_discount.available_users
5
+
6
+ %a#browse_users_popup_close.close{ :href => '#browse_users_popup_close' }
@@ -0,0 +1,11 @@
1
+ - discounted_type = user.class.to_s
2
+
3
+ - discounted_id = discounted_type != "ShopDiscountable" ? user.id : user.discounted_id
4
+ - discountable_id = discounted_type != "ShopDiscountable" ? nil : user.id
5
+ - success_element = discounted_type != "ShopDiscountable" ? 'discount_users' : 'available_users'
6
+ - class_type = discounted_type != "ShopDiscountable" ? 'available' : 'discounted'
7
+
8
+ %li.product{:class => "discountable #{class_type} user", :id => "#{class_type}_#{user.id}", :'data-discounted_id' => discounted_id, :'data-discounted_type' => discounted_type, :'data-discounted_type_human' => 'User', :'data-discountable_id' => discountable_id, :'data-success_element' => success_element }
9
+ %span.name= truncate((user.name rescue user.discounted.name), 30, '...')
10
+ .actions
11
+ %span.delete
@@ -6,6 +6,7 @@ en:
6
6
  new_discount: New Discount
7
7
  browse_products: Browse Products
8
8
  browse_categories: Browse Categories
9
+ browse_users: Browse Users
9
10
  amount: Amount
10
11
  code: Code
11
12
  starts: Starts On
@@ -4,7 +4,7 @@ module ShopDiscounts
4
4
 
5
5
  def self.included(base)
6
6
  base.class_eval do
7
- has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discounted_id
7
+ has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discounted_id, :dependent => :destroy
8
8
  has_many :discounts, :class_name => 'ShopDiscount', :through => :discountables
9
9
  end
10
10
  end
@@ -0,0 +1,24 @@
1
+ module ShopDiscounts
2
+ module Models
3
+ module FormLineItem
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ def create_with_discounts
9
+ @result = create_without_discounts
10
+
11
+ @order.discountables.each do |discountable|
12
+ discountable.create_shop_line_items_if_shop_order
13
+ end
14
+
15
+ @result
16
+ end
17
+ alias_method_chain :create, :discounts
18
+
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module ShopDiscounts
2
+ module Models
3
+ module ShopOrder
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ # Assigns discounts based off the customers discounts
9
+ def apply_customer_discounts
10
+ customer.discounts.each do |discount|
11
+ ShopDiscountable.create(:discount_id => discount.id, :discounted_id => self.id, :discounted_type => self.class.name)
12
+ end
13
+ end
14
+
15
+ class << self
16
+ alias_method :original_find_by_session, :find_by_session
17
+ def find_by_session(session)
18
+ if order = original_find_by_session(session)
19
+ order.apply_customer_discounts
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,6 @@
1
1
  module ShopDiscounts
2
2
  module Models
3
- module Product
3
+ module ShopProduct
4
4
 
5
5
  def self.included(base)
6
6
  base.class_eval do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-shop_discounts-extension}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dirk Kelly"]
12
- s.date = %q{2010-12-01}
12
+ s.date = %q{2010-12-17}
13
13
  s.description = %q{RadiantShop: Apply discounts to Products and Categories and have them accessed through codes}
14
14
  s.email = %q{dk@dirkkelly.com}
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "app/views/admin/shop/discounts/edit/_popups.html.haml",
36
36
  "app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml",
37
37
  "app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml",
38
+ "app/views/admin/shop/discounts/edit/buttons/_browse_users.html.haml",
38
39
  "app/views/admin/shop/discounts/edit/inputs/_amount.html.haml",
39
40
  "app/views/admin/shop/discounts/edit/inputs/_code.html.haml",
40
41
  "app/views/admin/shop/discounts/edit/inputs/_name.html.haml",
@@ -42,10 +43,13 @@ Gem::Specification.new do |s|
42
43
  "app/views/admin/shop/discounts/edit/meta/_start.html.haml",
43
44
  "app/views/admin/shop/discounts/edit/parts/_categories.html.haml",
44
45
  "app/views/admin/shop/discounts/edit/parts/_products.html.haml",
46
+ "app/views/admin/shop/discounts/edit/parts/_users.html.haml",
45
47
  "app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml",
46
48
  "app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml",
49
+ "app/views/admin/shop/discounts/edit/popups/_browse_users.html.haml",
47
50
  "app/views/admin/shop/discounts/edit/shared/_category.html.haml",
48
51
  "app/views/admin/shop/discounts/edit/shared/_product.html.haml",
52
+ "app/views/admin/shop/discounts/edit/shared/_user.html.haml",
49
53
  "app/views/admin/shop/discounts/index.html.haml",
50
54
  "app/views/admin/shop/discounts/index/_discount.html.haml",
51
55
  "app/views/admin/shop/discounts/index/_foot.html.haml",
@@ -61,8 +65,10 @@ Gem::Specification.new do |s|
61
65
  "features/support/paths.rb",
62
66
  "lib/radiant-shop_discounts-extension.rb",
63
67
  "lib/shop_discounts/models/discountable.rb",
64
- "lib/shop_discounts/models/product.rb",
68
+ "lib/shop_discounts/models/form_line_item.rb",
65
69
  "lib/shop_discounts/models/purchaseable.rb",
70
+ "lib/shop_discounts/models/shop_order.rb",
71
+ "lib/shop_discounts/models/shop_product.rb",
66
72
  "lib/shop_discounts/tags/cart.rb",
67
73
  "lib/shop_discounts/tags/item.rb",
68
74
  "lib/tasks/shop_discounts_extension_tasks.rake",
@@ -76,12 +82,14 @@ Gem::Specification.new do |s|
76
82
  "spec/datasets/shop_discountables.rb",
77
83
  "spec/datasets/shop_discounts.rb",
78
84
  "spec/lib/shop_discounts/models/discountable_spec.rb",
85
+ "spec/lib/shop_discounts/models/form_line_item_spec.rb",
79
86
  "spec/lib/shop_discounts/models/purchaseable_spec.rb",
80
87
  "spec/lib/shop_discounts/tags/item_spec.rb",
81
88
  "spec/models/form_discount_spec.rb",
82
89
  "spec/models/shop_category_spec.rb",
83
90
  "spec/models/shop_discount_spec.rb",
84
91
  "spec/models/shop_line_item_spec.rb",
92
+ "spec/models/shop_order_spec.rb",
85
93
  "spec/models/shop_product_spec.rb",
86
94
  "spec/spec.opts",
87
95
  "spec/spec_helper.rb"
@@ -97,12 +105,14 @@ Gem::Specification.new do |s|
97
105
  "spec/datasets/shop_discountables.rb",
98
106
  "spec/datasets/shop_discounts.rb",
99
107
  "spec/lib/shop_discounts/models/discountable_spec.rb",
108
+ "spec/lib/shop_discounts/models/form_line_item_spec.rb",
100
109
  "spec/lib/shop_discounts/models/purchaseable_spec.rb",
101
110
  "spec/lib/shop_discounts/tags/item_spec.rb",
102
111
  "spec/models/form_discount_spec.rb",
103
112
  "spec/models/shop_category_spec.rb",
104
113
  "spec/models/shop_discount_spec.rb",
105
114
  "spec/models/shop_line_item_spec.rb",
115
+ "spec/models/shop_order_spec.rb",
106
116
  "spec/models/shop_product_spec.rb",
107
117
  "spec/spec_helper.rb"
108
118
  ]
@@ -112,12 +122,12 @@ Gem::Specification.new do |s|
112
122
  s.specification_version = 3
113
123
 
114
124
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
115
- s.add_runtime_dependency(%q<radiant-shop-extension>, [">= 0"])
125
+ s.add_runtime_dependency(%q<radiant-shop-extension>, ["= 0.92.2"])
116
126
  else
117
- s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
127
+ s.add_dependency(%q<radiant-shop-extension>, ["= 0.92.2"])
118
128
  end
119
129
  else
120
- s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
130
+ s.add_dependency(%q<radiant-shop-extension>, ["= 0.92.2"])
121
131
  end
122
132
  end
123
133
 
@@ -18,11 +18,13 @@ class ShopDiscountsExtension < Radiant::Extension
18
18
 
19
19
  ShopLineItem.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::Purchaseable
20
20
 
21
- ShopProduct.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::Product
22
- ShopOrder.send :include, ShopDiscounts::Models::Discountable
21
+ ShopProduct.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::ShopProduct
22
+ ShopOrder.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::ShopOrder
23
23
  ShopCategory.send :include, ShopDiscounts::Models::Discountable
24
+ User.send :include, ShopDiscounts::Models::Discountable
24
25
 
25
- Page.send :include, ShopDiscounts::Tags::Cart, ShopDiscounts::Tags::Item
26
+ Page.send :include, ShopDiscounts::Tags::Cart, ShopDiscounts::Tags::Item
26
27
 
28
+ FormLineItem.send :include, ShopDiscounts::Models::FormLineItem
27
29
  end
28
30
  end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.dirname(__FILE__) + "/../../../../spec_helper"
2
2
 
3
3
  describe Admin::Shop::Discounts::DiscountablesController do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.dirname(__FILE__) + "/../../../spec_helper"
2
2
 
3
3
  describe Admin::Shop::DiscountsController do
4
4
 
@@ -13,11 +13,11 @@ describe Admin::Shop::DiscountsController do
13
13
  it 'should be assigned' do
14
14
  get :index
15
15
 
16
- assigns(:inputs).should === []
17
- assigns(:meta).should === []
18
- assigns(:buttons).should === ['new_discount']
19
- assigns(:parts).should === []
20
- assigns(:popups).should === []
16
+ assigns(:inputs).should include()
17
+ assigns(:meta).should include()
18
+ assigns(:buttons).should include('new_discount')
19
+ assigns(:parts).should include()
20
+ assigns(:popups).should include()
21
21
  end
22
22
  end
23
23
  end
@@ -27,11 +27,11 @@ describe Admin::Shop::DiscountsController do
27
27
  it 'should be assigned' do
28
28
  get :new
29
29
 
30
- assigns(:inputs).should === ['name','amount','code']
31
- assigns(:meta).should === ['start','finish']
32
- assigns(:buttons).should === []
33
- assigns(:parts).should === []
34
- assigns(:popups).should === []
30
+ assigns(:inputs).should include('name','amount','code')
31
+ assigns(:meta).should include('start','finish')
32
+ assigns(:buttons).should include()
33
+ assigns(:parts).should include()
34
+ assigns(:popups).should include()
35
35
  end
36
36
  end
37
37
  end
@@ -41,11 +41,11 @@ describe Admin::Shop::DiscountsController do
41
41
  it 'should be assigned' do
42
42
  get :edit, :id => shop_discounts(:ten_percent).id
43
43
 
44
- assigns(:inputs).should === ['name','amount','code']
45
- assigns(:meta).should === ['start','finish']
46
- assigns(:buttons).should === ['browse_categories', 'browse_products']
47
- assigns(:parts).should === ['categories', 'products']
48
- assigns(:popups).should === ['browse_categories', 'browse_products']
44
+ assigns(:inputs).should include('name','amount','code')
45
+ assigns(:meta).should include('start','finish')
46
+ assigns(:buttons).should include('browse_categories', 'browse_products','browse_users')
47
+ assigns(:parts).should include('categories', 'products','users')
48
+ assigns(:popups).should include('browse_categories', 'browse_products','browse_users')
49
49
  end
50
50
  end
51
51
  end
@@ -55,11 +55,11 @@ describe Admin::Shop::DiscountsController do
55
55
  it 'should be assigned' do
56
56
  post :create, :shop_variant => {}
57
57
 
58
- assigns(:inputs).should === ['name','amount','code']
59
- assigns(:meta).should === ['start','finish']
60
- assigns(:buttons).should === []
61
- assigns(:parts).should === []
62
- assigns(:popups).should === []
58
+ assigns(:inputs).should include('name','amount','code')
59
+ assigns(:meta).should include('start','finish')
60
+ assigns(:buttons).should include()
61
+ assigns(:parts).should include()
62
+ assigns(:popups).should include()
63
63
  end
64
64
  end
65
65
  end
@@ -69,11 +69,11 @@ describe Admin::Shop::DiscountsController do
69
69
  it 'should be assigned' do
70
70
  put :update, :id => shop_discounts(:ten_percent).id, :shop_variant => {}
71
71
 
72
- assigns(:inputs).should === ['name','amount','code']
73
- assigns(:meta).should === ['start','finish']
74
- assigns(:buttons).should === ['browse_categories', 'browse_products']
75
- assigns(:parts).should === ['categories', 'products']
76
- assigns(:popups).should === ['browse_categories', 'browse_products']
72
+ assigns(:inputs).should include('name','amount','code')
73
+ assigns(:meta).should include('start','finish')
74
+ assigns(:buttons).should include('browse_categories', 'browse_products','browse_users')
75
+ assigns(:parts).should include('categories', 'products','users')
76
+ assigns(:popups).should include('browse_categories', 'browse_products','browse_users')
77
77
  end
78
78
  end
79
79
  end
@@ -3,6 +3,24 @@ class FormsDiscountDataset < Dataset::Base
3
3
  uses :pages, :shop_discounts, :forms
4
4
 
5
5
  helpers do
6
+ def mock_valid_form_line_item_request
7
+ @form = forms(:checkout)
8
+ @form[:extensions] = {
9
+ :add_line_item => {
10
+ :extension => 'line_item',
11
+ :process => 'add'
12
+ }
13
+ }
14
+ @data = {
15
+ :line_item => {
16
+ :item_id => shop_line_items(:three).item.id,
17
+ :item_type => 'ShopProduct'
18
+ }
19
+ }
20
+
21
+ @request.session = { :shop_order => @order.id }
22
+ end
23
+
6
24
  def mock_valid_form_discount_request
7
25
  @form = forms(:checkout)
8
26
  @form[:extensions] = {
@@ -12,9 +30,9 @@ class FormsDiscountDataset < Dataset::Base
12
30
  }
13
31
  }
14
32
  @data = {
15
- :discount => {
16
- :code => shop_discounts(:ten_percent).code
17
- }
33
+ :discount => {
34
+ :code => shop_discounts(:ten_percent).code
35
+ }
18
36
  }
19
37
 
20
38
  @request.session = { :shop_order => @order.id }
@@ -1,22 +1,33 @@
1
1
  class ShopDiscountablesDataset < Dataset::Base
2
2
 
3
- uses :shop_discounts, :shop_products, :shop_categories
3
+ uses :shop_discounts, :shop_products, :shop_categories, :shop_orders
4
4
 
5
5
  def load
6
6
  create_record :shop_discountables, :ten_percent_bread,
7
- :discount_id => shop_discounts(:ten_percent).id,
8
- :discounted_id => shop_categories(:bread).id,
9
- :discounted_type => 'ShopCategory'
7
+ :discount_id => shop_discounts(:ten_percent).id,
8
+ :discounted_id => shop_categories(:bread).id,
9
+ :discounted_type => shop_categories(:bread).class.name
10
10
 
11
11
  create_record :shop_discountables, :five_percent_bread,
12
- :discount_id => shop_discounts(:five_percent).id,
13
- :discounted_id => shop_categories(:bread).id,
14
- :discounted_type => 'ShopCategory'
12
+ :discount_id => shop_discounts(:five_percent).id,
13
+ :discounted_id => shop_categories(:bread).id,
14
+ :discounted_type => shop_categories(:bread).class.name
15
15
 
16
16
  create_record :shop_discountables, :five_percent_crusty_bread,
17
- :discount_id => shop_discounts(:five_percent).id,
18
- :discounted_id => shop_products(:crusty_bread).id,
19
- :discounted_type => 'ShopProduct'
17
+ :discount_id => shop_discounts(:five_percent).id,
18
+ :discounted_id => shop_products(:crusty_bread).id,
19
+ :discounted_type => shop_products(:crusty_bread).class.name
20
+
21
+ create_record :shop_discountables, :several_items_five_percent,
22
+ :discount_id => shop_discounts(:five_percent).id,
23
+ :discounted_id => shop_orders(:several_items).id,
24
+ :discounted_type => shop_orders(:several_items).class.name
25
+
26
+ create_record :shop_discountables, :admin_ten_percent,
27
+ :discount_id => shop_discounts(:ten_percent).id,
28
+ :discounted_id => users(:admin).id,
29
+ :discounted_type => users(:admin).class.name
30
+
20
31
  end
21
32
 
22
33
  end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + "/../../../spec_helper"
2
+
3
+ describe ShopDiscounts::Models::FormLineItem do
4
+
5
+ dataset :forms_discount, :shop_discountables, :shop_orders, :shop_line_items
6
+
7
+ before :each do
8
+ mock_page_with_request_and_data
9
+ @order = shop_orders(:several_items)
10
+ mock_valid_form_line_item_request
11
+
12
+ @form_line_item = FormLineItem.new(@form, @page, @form[:extensions][:add_line_item])
13
+ end
14
+
15
+ it 'should define #create_with_discounts' do
16
+ @form_line_item.respond_to?('create_with_discounts').should be_true
17
+ end
18
+
19
+ it 'should call #create_shop_line_items_if_shop_order on the order' do
20
+ @discount = ShopDiscountable.new
21
+ mock(@discount).create_shop_line_items_if_shop_order { true }
22
+ mock(@order).discountables { [ @discount ] }
23
+ stub(ShopOrder).find(@order.id) { @order }
24
+
25
+ @form_line_item.create
26
+ end
27
+
28
+ end
@@ -2,7 +2,7 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe FormDiscount do
4
4
 
5
- dataset :forms_discount, :shop_discounts, :pages
5
+ dataset :forms_discount, :shop_discounts, :pages, :shop_customers
6
6
 
7
7
  before :each do
8
8
  mock_page_with_request_and_data
@@ -0,0 +1,32 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ShopOrder do
4
+ dataset :shop_orders, :shop_line_items, :shop_discountables, :shop_customers
5
+
6
+ context '#apply_customer_discounts' do
7
+
8
+ it ' should assign the orders customer' do
9
+ shop_orders(:several_items).discountables.should have(1).discountables
10
+ shop_orders(:several_items).apply_customer_discounts
11
+ shop_orders(:several_items).discountables.should have(2).discountables
12
+ end
13
+
14
+ end
15
+
16
+ context '.find_by_session' do
17
+
18
+ it 'should now call #apply_customer_discounts on the returned object' do
19
+ @order = shop_orders(:several_items)
20
+ mock(@order).apply_customer_discounts { true }
21
+ mock(ShopOrder).find(@order.id) { @order }
22
+
23
+ ShopOrder.find_by_session(@order.id)
24
+ end
25
+
26
+ it 'should return ActiveRecord::RecordNotFound if the order does not exist' do
27
+ expect{ ShopOrder.find_by_session(1) }.to raise_error(ActiveRecord::RecordNotFound)
28
+ end
29
+
30
+ end
31
+
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,13 +11,21 @@ unless defined? RADIANT_ROOT
11
11
  end
12
12
  require "#{RADIANT_ROOT}/spec/spec_helper"
13
13
 
14
- Dataset::Resolver.default << (File.dirname(__FILE__) + "/../../shop/spec/datasets")
15
- Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
14
+ require ShopExtension.root + '/spec/spec_helper'
16
15
 
17
- if File.directory?(File.dirname(__FILE__) + "/matchers")
18
- Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
19
- end
20
-
21
- Spec::Runner.configure do |config|
22
- config.mock_with :rr
16
+ unless defined? SHOP_DISCOUNTS_ROOT
17
+
18
+ SHOP_DISCOUNTS_ROOT = ShopDiscountsExtension.root + '/spec'
19
+
20
+ Dataset::Resolver.default << (SHOP_DISCOUNTS_ROOT + "/datasets")
21
+
22
+ Dir[SHOP_ROOT + "/matchers/*.rb"].each {|file| require file }
23
+ if File.directory?(SHOP_DISCOUNTS_ROOT + "/matchers")
24
+ Dir[SHOP_DISCOUNTS_ROOT + "/matchers/**/*.rb"].each {|file| require file }
25
+ end
26
+
27
+ Spec::Runner.configure do |config|
28
+ config.mock_with :rr
29
+ end
30
+
23
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-shop_discounts-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dirk Kelly
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-01 00:00:00 +08:00
18
+ date: 2010-12-17 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,12 +24,14 @@ dependencies:
24
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - "="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 363
30
30
  segments:
31
31
  - 0
32
- version: "0"
32
+ - 92
33
+ - 2
34
+ version: 0.92.2
33
35
  name: radiant-shop-extension
34
36
  requirement: *id001
35
37
  description: "RadiantShop: Apply discounts to Products and Categories and have them accessed through codes"
@@ -60,6 +62,7 @@ files:
60
62
  - app/views/admin/shop/discounts/edit/_popups.html.haml
61
63
  - app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml
62
64
  - app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml
65
+ - app/views/admin/shop/discounts/edit/buttons/_browse_users.html.haml
63
66
  - app/views/admin/shop/discounts/edit/inputs/_amount.html.haml
64
67
  - app/views/admin/shop/discounts/edit/inputs/_code.html.haml
65
68
  - app/views/admin/shop/discounts/edit/inputs/_name.html.haml
@@ -67,10 +70,13 @@ files:
67
70
  - app/views/admin/shop/discounts/edit/meta/_start.html.haml
68
71
  - app/views/admin/shop/discounts/edit/parts/_categories.html.haml
69
72
  - app/views/admin/shop/discounts/edit/parts/_products.html.haml
73
+ - app/views/admin/shop/discounts/edit/parts/_users.html.haml
70
74
  - app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml
71
75
  - app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml
76
+ - app/views/admin/shop/discounts/edit/popups/_browse_users.html.haml
72
77
  - app/views/admin/shop/discounts/edit/shared/_category.html.haml
73
78
  - app/views/admin/shop/discounts/edit/shared/_product.html.haml
79
+ - app/views/admin/shop/discounts/edit/shared/_user.html.haml
74
80
  - app/views/admin/shop/discounts/index.html.haml
75
81
  - app/views/admin/shop/discounts/index/_discount.html.haml
76
82
  - app/views/admin/shop/discounts/index/_foot.html.haml
@@ -86,8 +92,10 @@ files:
86
92
  - features/support/paths.rb
87
93
  - lib/radiant-shop_discounts-extension.rb
88
94
  - lib/shop_discounts/models/discountable.rb
89
- - lib/shop_discounts/models/product.rb
95
+ - lib/shop_discounts/models/form_line_item.rb
90
96
  - lib/shop_discounts/models/purchaseable.rb
97
+ - lib/shop_discounts/models/shop_order.rb
98
+ - lib/shop_discounts/models/shop_product.rb
91
99
  - lib/shop_discounts/tags/cart.rb
92
100
  - lib/shop_discounts/tags/item.rb
93
101
  - lib/tasks/shop_discounts_extension_tasks.rake
@@ -101,12 +109,14 @@ files:
101
109
  - spec/datasets/shop_discountables.rb
102
110
  - spec/datasets/shop_discounts.rb
103
111
  - spec/lib/shop_discounts/models/discountable_spec.rb
112
+ - spec/lib/shop_discounts/models/form_line_item_spec.rb
104
113
  - spec/lib/shop_discounts/models/purchaseable_spec.rb
105
114
  - spec/lib/shop_discounts/tags/item_spec.rb
106
115
  - spec/models/form_discount_spec.rb
107
116
  - spec/models/shop_category_spec.rb
108
117
  - spec/models/shop_discount_spec.rb
109
118
  - spec/models/shop_line_item_spec.rb
119
+ - spec/models/shop_order_spec.rb
110
120
  - spec/models/shop_product_spec.rb
111
121
  - spec/spec.opts
112
122
  - spec/spec_helper.rb
@@ -151,11 +161,13 @@ test_files:
151
161
  - spec/datasets/shop_discountables.rb
152
162
  - spec/datasets/shop_discounts.rb
153
163
  - spec/lib/shop_discounts/models/discountable_spec.rb
164
+ - spec/lib/shop_discounts/models/form_line_item_spec.rb
154
165
  - spec/lib/shop_discounts/models/purchaseable_spec.rb
155
166
  - spec/lib/shop_discounts/tags/item_spec.rb
156
167
  - spec/models/form_discount_spec.rb
157
168
  - spec/models/shop_category_spec.rb
158
169
  - spec/models/shop_discount_spec.rb
159
170
  - spec/models/shop_line_item_spec.rb
171
+ - spec/models/shop_order_spec.rb
160
172
  - spec/models/shop_product_spec.rb
161
173
  - spec/spec_helper.rb