radiant-shop_packages-extension 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +2 -0
  2. data/README +3 -0
  3. data/Rakefile +138 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/.DS_Store +0 -0
  6. data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
  7. data/app/controllers/admin/shop/packages_controller.rb +63 -0
  8. data/app/datasets/shop_packages.rb +25 -0
  9. data/app/models/shop_package.rb +79 -0
  10. data/app/models/shop_packing.rb +22 -0
  11. data/app/views/admin/shop/packages/edit.html.haml +11 -0
  12. data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
  13. data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
  14. data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
  15. data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
  16. data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
  17. data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
  18. data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
  19. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
  20. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
  21. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
  22. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
  23. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
  24. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
  25. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
  26. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
  27. data/app/views/admin/shop/packages/index.html.haml +13 -0
  28. data/app/views/admin/shop/packages/index/_foot.html.haml +8 -0
  29. data/app/views/admin/shop/packages/index/_head.html.haml +2 -0
  30. data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
  31. data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +1 -0
  32. data/app/views/admin/shop/packages/new.html.haml +11 -0
  33. data/app/views/admin/shop/packages/remove.html.haml +12 -0
  34. data/config/locales/en.yml +11 -0
  35. data/config/routes.rb +13 -0
  36. data/cucumber.yml +1 -0
  37. data/db/migrate/20101015161749_setup_shop_packages.rb +27 -0
  38. data/lib/shop_packages/interface/packages.rb +34 -0
  39. data/lib/shop_packages/models/shop_packageable.rb +15 -0
  40. data/lib/shop_packages/tags/helpers.rb +41 -0
  41. data/lib/shop_packages/tags/package.rb +94 -0
  42. data/lib/tasks/shop_packages_extension_tasks.rake +55 -0
  43. data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
  44. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
  45. data/radiant-shop_packages-extension.gemspec +104 -0
  46. data/shop_packages_extension.rb +37 -0
  47. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
  48. data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
  49. data/spec/datasets/shop_packages.rb +23 -0
  50. data/spec/lib/shop_packages/tags/package_spec.rb +348 -0
  51. data/spec/models/shop_package_spec.rb +117 -0
  52. data/spec/models/shop_packing_spec.rb +67 -0
  53. data/spec/models/shop_product_spec.rb +25 -0
  54. data/spec/spec.opts +4 -0
  55. data/spec/spec_helper.rb +23 -0
  56. metadata +141 -0
@@ -0,0 +1,117 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ShopPackage do
4
+
5
+ dataset :shop_packages
6
+
7
+ before(:each) do
8
+ @package = shop_packages(:all_bread)
9
+ end
10
+
11
+ describe 'attributes' do
12
+
13
+ it 'should have a name' do
14
+ @package.name.should == 'all bread'
15
+ end
16
+
17
+ it 'should have a price' do
18
+ @package.price.should === 10.00
19
+ end
20
+
21
+ end
22
+
23
+ describe 'validation' do
24
+
25
+ it 'should require a name' do
26
+ @package = ShopPackage.new
27
+
28
+ @package.valid? === false
29
+
30
+ @package.name = "name"
31
+ @package.valid? === true
32
+ end
33
+
34
+ it 'should validate but not require the price' do
35
+ @package = ShopPackage.new({ :name => 'name' })
36
+ @package.valid? === true
37
+
38
+ @package.price = "asdas"
39
+ @package.valid? === false
40
+
41
+ @package.price = "-999.99"
42
+ @package.valid? === false
43
+
44
+ @package.price = "9.99.99"
45
+ @package.valid? === false
46
+
47
+ @package.price = "0.00"
48
+ @package.valid? === false
49
+
50
+ @package.price = "0.01"
51
+ @package.valid? === true
52
+
53
+ @package.price = "999999.99"
54
+ @package.valid? === true
55
+ end
56
+
57
+ it 'should generate a valid sku on validation' do
58
+ @package = ShopPackage.new({ :name => "dark_ _:_;_=_+_._~_toasted" })
59
+
60
+ @package.valid? === true
61
+ @package.sku.should === 'dark_______________toasted'
62
+ end
63
+
64
+ it 'should have an array of products' do
65
+ @package.products.class.should == Array
66
+ end
67
+
68
+ it 'should have an array of line_items' do
69
+ @package.line_items.class.should == Array
70
+ end
71
+
72
+ it 'should have an array of orders' do
73
+ @package.orders.class.should == Array
74
+ end
75
+
76
+ end
77
+
78
+ context 'instance methods' do
79
+
80
+ describe '#value' do
81
+ it 'should return the total value of its products' do
82
+ value = 0
83
+ @package.packings.map { |pkg| value += (pkg.product.price.to_f * pkg.quantity) }
84
+
85
+ @package.value.should === value
86
+ end
87
+ end
88
+
89
+ describe '#weight' do
90
+ it 'should return the total value of its products' do
91
+ weight = 0
92
+ @package.packings.map { |pkg| weight += (pkg.product.weight.to_f * pkg.quantity) }
93
+
94
+ @package.weight.should === weight
95
+ end
96
+ end
97
+
98
+ describe '#available_products' do
99
+ it 'should return the subset of products not in that package' do
100
+ @package.available_products.should === (ShopProduct.all - @package.products)
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+
107
+ context 'Class Methods' do
108
+
109
+ describe '#params' do
110
+ it 'should have a set of standard parameters' do
111
+ ShopPackage.attrs.should === [ :id, :name,:price, :sku, :description, :created_at, :updated_at ]
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ShopPacking do
4
+
5
+ dataset :shop_packages
6
+
7
+ before(:each) do
8
+ @packing = shop_packings(:warm_bread)
9
+ end
10
+
11
+ describe 'attributes' do
12
+
13
+ it 'should have a quantity' do
14
+ @packing.quantity.should == 1
15
+ end
16
+
17
+ it 'should have a position' do
18
+ @packing.position.should == 1
19
+ end
20
+
21
+ it 'should have a package' do
22
+ @packing.package.class.should == ShopPackage
23
+ end
24
+
25
+ it 'should have a product' do
26
+ @packing.product.class.should == ShopProduct
27
+ end
28
+
29
+ end
30
+
31
+ context 'instance methods' do
32
+
33
+ describe '#value' do
34
+
35
+ it 'should return the quantity multiplied by the product price' do
36
+ @packing.value.should === @packing.quantity * @packing.product.price.to_f
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ context 'Class Methods' do
44
+
45
+ describe '#set_quantity' do
46
+ it 'should return the highest of 1 or the quantity' do
47
+ @packing.quantity = 0
48
+ @packing.save
49
+ @packing.quantity.should === 1
50
+
51
+ @packing.quantity = 1
52
+ @packing.save
53
+ @packing.quantity.should === 1
54
+
55
+ @packing.quantity = -1
56
+ @packing.save
57
+ @packing.quantity.should === 1
58
+
59
+ @packing.quantity = 2
60
+ @packing.save
61
+ @packing.quantity.should === 2
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ShopProduct do
4
+ dataset :shop_products, :shop_packages
5
+
6
+ describe 'relationships' do
7
+ before :each do
8
+ @product = shop_products(:crusty_bread)
9
+ end
10
+
11
+ it 'should have many packings' do
12
+ @product.packings.is_a?(Array).should be_true
13
+ end
14
+
15
+ it 'should have many packages' do
16
+ @product.packages.is_a?(Array).should be_true
17
+ end
18
+
19
+ it 'should have many related' do
20
+ @product.related.is_a?(Array).should be_true
21
+ end
22
+
23
+ end
24
+
25
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,23 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/../../shop/spec/datasets")
15
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
16
+
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
23
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-shop_packages-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Dirk Kelly
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-10 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ name: radiant-shop-extension
34
+ requirement: *id001
35
+ description: "RadiantShop: Group up Products into packages, you can assign a price to a package"
36
+ email: dk@dirkkelly.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ files:
44
+ - .gitignore
45
+ - README
46
+ - Rakefile
47
+ - VERSION
48
+ - app/controllers/.DS_Store
49
+ - app/controllers/admin/shop/packages/packings_controller.rb
50
+ - app/controllers/admin/shop/packages_controller.rb
51
+ - app/datasets/shop_packages.rb
52
+ - app/models/shop_package.rb
53
+ - app/models/shop_packing.rb
54
+ - app/views/admin/shop/packages/edit.html.haml
55
+ - app/views/admin/shop/packages/edit/_foot.html.haml
56
+ - app/views/admin/shop/packages/edit/_form.html.haml
57
+ - app/views/admin/shop/packages/edit/_head.html.haml
58
+ - app/views/admin/shop/packages/edit/_inputs.html.haml
59
+ - app/views/admin/shop/packages/edit/_meta.html.haml
60
+ - app/views/admin/shop/packages/edit/_parts.html.haml
61
+ - app/views/admin/shop/packages/edit/_popups.html.haml
62
+ - app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml
63
+ - app/views/admin/shop/packages/edit/inputs/_name.html.haml
64
+ - app/views/admin/shop/packages/edit/inputs/_price.html.haml
65
+ - app/views/admin/shop/packages/edit/meta/_sku.html.haml
66
+ - app/views/admin/shop/packages/edit/parts/_description.html.haml
67
+ - app/views/admin/shop/packages/edit/parts/_products.html.haml
68
+ - app/views/admin/shop/packages/edit/popups/_browse_products.html.haml
69
+ - app/views/admin/shop/packages/edit/shared/_product.html.haml
70
+ - app/views/admin/shop/packages/index.html.haml
71
+ - app/views/admin/shop/packages/index/_foot.html.haml
72
+ - app/views/admin/shop/packages/index/_head.html.haml
73
+ - app/views/admin/shop/packages/index/_package.html.haml
74
+ - app/views/admin/shop/packages/index/buttons/_new_package.html.haml
75
+ - app/views/admin/shop/packages/new.html.haml
76
+ - app/views/admin/shop/packages/remove.html.haml
77
+ - config/locales/en.yml
78
+ - config/routes.rb
79
+ - cucumber.yml
80
+ - db/migrate/20101015161749_setup_shop_packages.rb
81
+ - lib/shop_packages/interface/packages.rb
82
+ - lib/shop_packages/models/shop_packageable.rb
83
+ - lib/shop_packages/tags/helpers.rb
84
+ - lib/shop_packages/tags/package.rb
85
+ - lib/tasks/shop_packages_extension_tasks.rake
86
+ - public/javascripts/admin/extensions/shop/packages/edit.js
87
+ - public/stylesheets/sass/admin/extensions/shop/packages/edit.sass
88
+ - radiant-shop_packages-extension.gemspec
89
+ - shop_packages_extension.rb
90
+ - spec/controllers/admin/shop/packages/packings_controller_spec.rb
91
+ - spec/controllers/admin/shop/packages_controller_spec.rb
92
+ - spec/datasets/shop_packages.rb
93
+ - spec/lib/shop_packages/tags/package_spec.rb
94
+ - spec/models/shop_package_spec.rb
95
+ - spec/models/shop_packing_spec.rb
96
+ - spec/models/shop_product_spec.rb
97
+ - spec/spec.opts
98
+ - spec/spec_helper.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/thefrontiergroup/radiant-shop_packages-extension
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --charset=UTF-8
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.7
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Shop Packages Extension for Radiant CMS
133
+ test_files:
134
+ - spec/controllers/admin/shop/packages/packings_controller_spec.rb
135
+ - spec/controllers/admin/shop/packages_controller_spec.rb
136
+ - spec/datasets/shop_packages.rb
137
+ - spec/lib/shop_packages/tags/package_spec.rb
138
+ - spec/models/shop_package_spec.rb
139
+ - spec/models/shop_packing_spec.rb
140
+ - spec/models/shop_product_spec.rb
141
+ - spec/spec_helper.rb