radiant-shop_packages-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/VERSION +1 -1
- data/app/views/admin/shop/discounts/edit/buttons/_browse_packages.html.haml +1 -0
- data/app/views/admin/shop/discounts/edit/parts/_packages.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/popups/_browse_packages.html.haml +6 -0
- data/app/views/admin/shop/discounts/edit/shared/_package.html.haml +11 -0
- data/config/locales/en.yml +1 -0
- data/lib/shop_packages/controllers/discounts_controller.rb +22 -0
- data/lib/shop_packages/models/shop_discount.rb +19 -0
- data/lib/shop_packages/models/shop_discountable.rb +15 -0
- data/radiant-shop_packages-extension.gemspec +15 -2
- data/shop_packages_extension.rb +5 -2
- data/spec/controllers/admin/shop/discounts_controller_spec.rb +27 -0
- data/spec/datasets/shop_packages.rb +4 -3
- data/spec/models/shop_discount_spec.rb +17 -0
- data/spec/models/shop_discountable_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -0
- metadata +17 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1 @@
|
|
1
|
+
= link_to t('browse_packages'), '#browse_packages_popup', :class => 'popup button'
|
@@ -0,0 +1,6 @@
|
|
1
|
+
%h3.title= t('browse_packages')
|
2
|
+
|
3
|
+
%ul#available_packages.availables
|
4
|
+
= render :partial => '/admin/shop/discounts/edit/shared/package', :collection => @shop_discount.available_packages
|
5
|
+
|
6
|
+
%a#browse_packages_popup_close.close{ :href => '#browse_packages_popup_close' }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- discounted_type = package.class.to_s
|
2
|
+
|
3
|
+
- discounted_id = discounted_type != "ShopDiscountable" ? package.id : package.discounted_id
|
4
|
+
- discountable_id = discounted_type != "ShopDiscountable" ? nil : package.id
|
5
|
+
- success_element = discounted_type != "ShopDiscountable" ? 'discount_packages' : 'available_packages'
|
6
|
+
- class_type = discounted_type != "ShopDiscountable" ? 'available' : 'discounted'
|
7
|
+
|
8
|
+
%li.product{:class => "discountable #{class_type} package", :id => "#{class_type}_#{package.id}", :'data-discounted_id' => discounted_id, :'data-discounted_type' => discounted_type, :'data-discounted_type_human' => 'Package', :'data-discountable_id' => discountable_id, :'data-success_element' => success_element }
|
9
|
+
%span.name= truncate((package.name rescue package.discounted.name), 30, '...')
|
10
|
+
.actions
|
11
|
+
%span.delete
|
data/config/locales/en.yml
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module ShopPackages
|
2
|
+
module Controllers
|
3
|
+
module DiscountsController
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
|
8
|
+
def config_edit_with_packages
|
9
|
+
config_edit_without_packages
|
10
|
+
|
11
|
+
@buttons << 'browse_packages'
|
12
|
+
@parts << 'packages'
|
13
|
+
@popups << 'browse_packages'
|
14
|
+
end
|
15
|
+
alias_method_chain :config_edit, :packages
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ShopPackages
|
2
|
+
module Models
|
3
|
+
module ShopDiscount
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
|
8
|
+
has_many :packages, :through => :discountables, :source => :package, :conditions => "shop_discountables.discounted_type = 'ShopPackage'"
|
9
|
+
|
10
|
+
def available_packages
|
11
|
+
ShopPackage.all - packages
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-shop_packages-extension}
|
8
|
-
s.version = "0.0.
|
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-
|
12
|
+
s.date = %q{2010-12-17}
|
13
13
|
s.description = %q{RadiantShop: Group up Products into packages, you can assign a price to a package}
|
14
14
|
s.email = %q{dk@dirkkelly.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,6 +25,10 @@ Gem::Specification.new do |s|
|
|
25
25
|
"app/datasets/shop_packages.rb",
|
26
26
|
"app/models/shop_package.rb",
|
27
27
|
"app/models/shop_packing.rb",
|
28
|
+
"app/views/admin/shop/discounts/edit/buttons/_browse_packages.html.haml",
|
29
|
+
"app/views/admin/shop/discounts/edit/parts/_packages.html.haml",
|
30
|
+
"app/views/admin/shop/discounts/edit/popups/_browse_packages.html.haml",
|
31
|
+
"app/views/admin/shop/discounts/edit/shared/_package.html.haml",
|
28
32
|
"app/views/admin/shop/packages/edit.html.haml",
|
29
33
|
"app/views/admin/shop/packages/edit/_foot.html.haml",
|
30
34
|
"app/views/admin/shop/packages/edit/_form.html.haml",
|
@@ -53,7 +57,10 @@ Gem::Specification.new do |s|
|
|
53
57
|
"cucumber.yml",
|
54
58
|
"db/migrate/20101015161749_setup_shop_packages.rb",
|
55
59
|
"lib/radiant-shop_packages-extension.rb",
|
60
|
+
"lib/shop_packages/controllers/discounts_controller.rb",
|
56
61
|
"lib/shop_packages/interface/packages.rb",
|
62
|
+
"lib/shop_packages/models/shop_discount.rb",
|
63
|
+
"lib/shop_packages/models/shop_discountable.rb",
|
57
64
|
"lib/shop_packages/models/shop_packageable.rb",
|
58
65
|
"lib/shop_packages/tags/helpers.rb",
|
59
66
|
"lib/shop_packages/tags/package.rb",
|
@@ -62,10 +69,13 @@ Gem::Specification.new do |s|
|
|
62
69
|
"public/stylesheets/sass/admin/extensions/shop/packages/edit.sass",
|
63
70
|
"radiant-shop_packages-extension.gemspec",
|
64
71
|
"shop_packages_extension.rb",
|
72
|
+
"spec/controllers/admin/shop/discounts_controller_spec.rb",
|
65
73
|
"spec/controllers/admin/shop/packages/packings_controller_spec.rb",
|
66
74
|
"spec/controllers/admin/shop/packages_controller_spec.rb",
|
67
75
|
"spec/datasets/shop_packages.rb",
|
68
76
|
"spec/lib/shop_packages/tags/package_spec.rb",
|
77
|
+
"spec/models/shop_discount_spec.rb",
|
78
|
+
"spec/models/shop_discountable_spec.rb",
|
69
79
|
"spec/models/shop_package_spec.rb",
|
70
80
|
"spec/models/shop_packing_spec.rb",
|
71
81
|
"spec/models/shop_product_spec.rb",
|
@@ -77,10 +87,13 @@ Gem::Specification.new do |s|
|
|
77
87
|
s.rubygems_version = %q{1.3.7}
|
78
88
|
s.summary = %q{Shop Packages Extension for Radiant CMS}
|
79
89
|
s.test_files = [
|
90
|
+
"spec/controllers/admin/shop/discounts_controller_spec.rb",
|
80
91
|
"spec/controllers/admin/shop/packages/packings_controller_spec.rb",
|
81
92
|
"spec/controllers/admin/shop/packages_controller_spec.rb",
|
82
93
|
"spec/datasets/shop_packages.rb",
|
83
94
|
"spec/lib/shop_packages/tags/package_spec.rb",
|
95
|
+
"spec/models/shop_discount_spec.rb",
|
96
|
+
"spec/models/shop_discountable_spec.rb",
|
84
97
|
"spec/models/shop_package_spec.rb",
|
85
98
|
"spec/models/shop_packing_spec.rb",
|
86
99
|
"spec/models/shop_product_spec.rb",
|
data/shop_packages_extension.rb
CHANGED
@@ -26,8 +26,11 @@ class ShopPackagesExtension < Radiant::Extension
|
|
26
26
|
ShopProduct.send :include, ShopPackages::Models::ShopPackageable
|
27
27
|
Page.send :include, ShopPackages::Tags::Package
|
28
28
|
|
29
|
-
if
|
30
|
-
ShopPackage.send
|
29
|
+
if defined?(ShopDiscount)
|
30
|
+
ShopPackage.send :include, ShopDiscounts::Models::Discountable
|
31
|
+
Admin::Shop::DiscountsController.send :include, ShopPackages::Controllers::DiscountsController
|
32
|
+
ShopDiscount.send :include, ShopPackages::Models::ShopDiscount
|
33
|
+
ShopDiscountable.send :include, ShopPackages::Models::ShopDiscountable
|
31
34
|
end
|
32
35
|
|
33
36
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../../spec_helper"
|
2
|
+
|
3
|
+
describe Admin::Shop::DiscountsController do
|
4
|
+
|
5
|
+
dataset :users, :shop_discounts
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
login_as users(:admin)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should assign packages to the #edit method' do
|
12
|
+
get :edit, :id => shop_discounts(:ten_percent).id
|
13
|
+
|
14
|
+
assigns(:buttons).include?('browse_packages').should be_true
|
15
|
+
assigns(:parts).include?('packages').should be_true
|
16
|
+
assigns(:popups).include?('browse_packages').should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should assign packages to the #edit method' do
|
20
|
+
put :update, :id => shop_discounts(:ten_percent).id
|
21
|
+
|
22
|
+
assigns(:buttons).include?('browse_packages').should be_true
|
23
|
+
assigns(:parts).include?('packages').should be_true
|
24
|
+
assigns(:popups).include?('browse_packages').should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -3,7 +3,8 @@ class ShopPackagesDataset < Dataset::Base
|
|
3
3
|
|
4
4
|
def load
|
5
5
|
packages = {
|
6
|
-
:bread => [ :soft, :crusty, :warm ]
|
6
|
+
:bread => [ :soft, :crusty, :warm ],
|
7
|
+
:milk => [ :full, :hilo, :choc ]
|
7
8
|
}
|
8
9
|
packages.each do |package, products|
|
9
10
|
create_record :shop_package, "all_#{package.to_s}".to_sym,
|
@@ -12,11 +13,11 @@ class ShopPackagesDataset < Dataset::Base
|
|
12
13
|
:price => 1 * 10
|
13
14
|
|
14
15
|
products.each_with_index do |product, i|
|
15
|
-
create_record :shop_packing, "#{product.to_s}
|
16
|
+
create_record :shop_packing, "#{product.to_s}_#{package.to_s}".to_s.to_sym,
|
16
17
|
:quantity => 1,
|
17
18
|
:position => 1,
|
18
19
|
:package => shop_packages("all_#{package.to_s}".to_sym),
|
19
|
-
:product => shop_products("#{product.to_s}
|
20
|
+
:product => shop_products("#{product.to_s}_#{package.to_s}".to_sym)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe ShopDiscount do
|
4
|
+
|
5
|
+
dataset :shop_packages, :shop_discounts
|
6
|
+
|
7
|
+
it 'should have many #packages' do
|
8
|
+
shop_discounts(:ten_percent).packages.is_a?(Array).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return a subset through #available_attributes' do
|
12
|
+
shop_discounts(:ten_percent).available_packages.should have(ShopPackage.all.count).packages
|
13
|
+
shop_discounts(:ten_percent).discountables.create(:discounted_id => shop_packages(:all_bread).id, :discounted_type => shop_packages(:all_bread).class.name)
|
14
|
+
shop_discounts(:ten_percent).available_packages.should have(ShopPackage.all.count-1).packages
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
describe ShopDiscountable do
|
4
|
+
|
5
|
+
dataset :shop_packages, :shop_discounts
|
6
|
+
|
7
|
+
it 'should have a #package' do
|
8
|
+
@discountable = ShopDiscountable.new
|
9
|
+
@discountable.package = shop_packages(:all_bread)
|
10
|
+
@discountable.package.is_a?(ShopPackage).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ end
|
|
12
12
|
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
13
|
|
14
14
|
Dataset::Resolver.default << (File.dirname(__FILE__) + "/../../shop/spec/datasets")
|
15
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/../../shop_discounts/spec/datasets")
|
15
16
|
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
16
17
|
|
17
18
|
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-shop_packages-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2010-12-17 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,10 @@ files:
|
|
50
50
|
- app/datasets/shop_packages.rb
|
51
51
|
- app/models/shop_package.rb
|
52
52
|
- app/models/shop_packing.rb
|
53
|
+
- app/views/admin/shop/discounts/edit/buttons/_browse_packages.html.haml
|
54
|
+
- app/views/admin/shop/discounts/edit/parts/_packages.html.haml
|
55
|
+
- app/views/admin/shop/discounts/edit/popups/_browse_packages.html.haml
|
56
|
+
- app/views/admin/shop/discounts/edit/shared/_package.html.haml
|
53
57
|
- app/views/admin/shop/packages/edit.html.haml
|
54
58
|
- app/views/admin/shop/packages/edit/_foot.html.haml
|
55
59
|
- app/views/admin/shop/packages/edit/_form.html.haml
|
@@ -78,7 +82,10 @@ files:
|
|
78
82
|
- cucumber.yml
|
79
83
|
- db/migrate/20101015161749_setup_shop_packages.rb
|
80
84
|
- lib/radiant-shop_packages-extension.rb
|
85
|
+
- lib/shop_packages/controllers/discounts_controller.rb
|
81
86
|
- lib/shop_packages/interface/packages.rb
|
87
|
+
- lib/shop_packages/models/shop_discount.rb
|
88
|
+
- lib/shop_packages/models/shop_discountable.rb
|
82
89
|
- lib/shop_packages/models/shop_packageable.rb
|
83
90
|
- lib/shop_packages/tags/helpers.rb
|
84
91
|
- lib/shop_packages/tags/package.rb
|
@@ -87,10 +94,13 @@ files:
|
|
87
94
|
- public/stylesheets/sass/admin/extensions/shop/packages/edit.sass
|
88
95
|
- radiant-shop_packages-extension.gemspec
|
89
96
|
- shop_packages_extension.rb
|
97
|
+
- spec/controllers/admin/shop/discounts_controller_spec.rb
|
90
98
|
- spec/controllers/admin/shop/packages/packings_controller_spec.rb
|
91
99
|
- spec/controllers/admin/shop/packages_controller_spec.rb
|
92
100
|
- spec/datasets/shop_packages.rb
|
93
101
|
- spec/lib/shop_packages/tags/package_spec.rb
|
102
|
+
- spec/models/shop_discount_spec.rb
|
103
|
+
- spec/models/shop_discountable_spec.rb
|
94
104
|
- spec/models/shop_package_spec.rb
|
95
105
|
- spec/models/shop_packing_spec.rb
|
96
106
|
- spec/models/shop_product_spec.rb
|
@@ -131,10 +141,13 @@ signing_key:
|
|
131
141
|
specification_version: 3
|
132
142
|
summary: Shop Packages Extension for Radiant CMS
|
133
143
|
test_files:
|
144
|
+
- spec/controllers/admin/shop/discounts_controller_spec.rb
|
134
145
|
- spec/controllers/admin/shop/packages/packings_controller_spec.rb
|
135
146
|
- spec/controllers/admin/shop/packages_controller_spec.rb
|
136
147
|
- spec/datasets/shop_packages.rb
|
137
148
|
- spec/lib/shop_packages/tags/package_spec.rb
|
149
|
+
- spec/models/shop_discount_spec.rb
|
150
|
+
- spec/models/shop_discountable_spec.rb
|
138
151
|
- spec/models/shop_package_spec.rb
|
139
152
|
- spec/models/shop_packing_spec.rb
|
140
153
|
- spec/models/shop_product_spec.rb
|