radiant-shop_variants-extension 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README +3 -0
- data/Rakefile +138 -0
- data/VERSION +1 -0
- data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
- data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
- data/app/controllers/admin/shop/variants_controller.rb +48 -0
- data/app/models/shop_product_variant.rb +36 -0
- data/app/models/shop_variant.rb +23 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
- data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
- data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
- data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
- data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
- data/app/views/admin/shop/variants/edit.html.haml +11 -0
- data/app/views/admin/shop/variants/index/_foot.html.haml +5 -0
- data/app/views/admin/shop/variants/index/_head.html.haml +2 -0
- data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
- data/app/views/admin/shop/variants/index/buttons/_add_variant.html.haml +1 -0
- data/app/views/admin/shop/variants/index/buttons/_categories.html.haml +1 -0
- data/app/views/admin/shop/variants/index.html.haml +13 -0
- data/app/views/admin/shop/variants/new.html.haml +11 -0
- data/app/views/admin/shop/variants/remove.html.haml +12 -0
- data/config/locales/en.yml +14 -0
- data/config/routes.rb +16 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20101015162238_setup_shop_variants.rb +21 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop_variants/controllers/products_controller.rb +44 -0
- data/lib/shop_variants/interface/variants.rb +34 -0
- data/lib/shop_variants/models/product.rb +15 -0
- data/lib/shop_variants/tags/helpers.rb +29 -0
- data/lib/shop_variants/tags/product_variant.rb +52 -0
- data/lib/tasks/shop_variants_extension_tasks.rake +55 -0
- data/public/javascripts/admin/extensions/shop/variants/edit.js +38 -0
- data/public/stylesheets/sass/admin/extensions/shop/variants/edit.sass +0 -0
- data/radiant-shop_variants-extension.gemspec +114 -0
- data/shop_variants_extension.rb +21 -0
- data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
- data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
- data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
- data/spec/datasets/shop_product_variants.rb +22 -0
- data/spec/datasets/shop_variants.rb +17 -0
- data/spec/lib/shop_variants/tags/helpers_spec.rb +59 -0
- data/spec/lib/shop_variants/tags/product_variant_spec.rb +175 -0
- data/spec/models/shop_product_spec.rb +15 -0
- data/spec/models/shop_product_variant_spec.rb +92 -0
- data/spec/models/shop_variant_spec.rb +32 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +23 -0
- metadata +151 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
module ShopVariants
|
2
|
+
module Controllers
|
3
|
+
module ProductsController
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
before_filter :config_global_variants
|
8
|
+
before_filter :config_index_variants, :only => [ :index ]
|
9
|
+
before_filter :config_edit_variants, :only => [ :edit, :update ]
|
10
|
+
before_filter :assets_edit_variants, :only => [ :edit, :update ]
|
11
|
+
|
12
|
+
def config_global_variants
|
13
|
+
@parts << 'variants'
|
14
|
+
end
|
15
|
+
|
16
|
+
def config_index_variants
|
17
|
+
@buttons << 'variants'
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_edit_variants
|
21
|
+
@buttons << 'browse_templates'
|
22
|
+
@buttons << 'new_variant'
|
23
|
+
|
24
|
+
@popups << 'browse_templates'
|
25
|
+
@popups << 'new_variant'
|
26
|
+
end
|
27
|
+
|
28
|
+
def assets_edit_variants
|
29
|
+
include_stylesheet 'admin/extensions/shop/variants/edit'
|
30
|
+
|
31
|
+
include_javascript 'admin/extensions/shop/variants/edit'
|
32
|
+
|
33
|
+
@routes << {
|
34
|
+
:name => 'admin_shop_product_variant_path',
|
35
|
+
:path => admin_shop_product_variant_path(@shop_product, ':id')
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ShopVariants
|
2
|
+
module Interface
|
3
|
+
module Variants
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
attr_accessor :variants
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def load_default_shop_variants_regions
|
15
|
+
returning OpenStruct.new do |variants|
|
16
|
+
variants.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
17
|
+
edit.main.concat %w{head form popups}
|
18
|
+
edit.form.concat %w{inputs meta parts foot}
|
19
|
+
edit.foot.concat %w{buttons timestamp}
|
20
|
+
end
|
21
|
+
variants.new = variants.edit
|
22
|
+
variants.index = Radiant::AdminUI::RegionSet.new do |index|
|
23
|
+
index.head.concat %w{}
|
24
|
+
index.body.concat %w{name modify}
|
25
|
+
index.foot.concat %w{buttons}
|
26
|
+
end
|
27
|
+
variants.remove = variants.index
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ShopVariants
|
2
|
+
module Models
|
3
|
+
module Product
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
has_many :variants, :class_name => 'ShopProductVariant', :foreign_key => :product_id, :dependent => :destroy
|
8
|
+
|
9
|
+
accepts_nested_attributes_for :variants
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ShopVariants
|
2
|
+
module Tags
|
3
|
+
class Helpers
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def current_product_variants(tag)
|
7
|
+
result = nil
|
8
|
+
|
9
|
+
if tag.locals.shop_product.present?
|
10
|
+
result = tag.locals.shop_product.variants
|
11
|
+
end
|
12
|
+
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_product_variant(tag)
|
17
|
+
result = nil
|
18
|
+
|
19
|
+
if tag.locals.shop_product_variant.present?
|
20
|
+
result = tag.locals.shop_product_variant
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ShopVariants
|
2
|
+
module Tags
|
3
|
+
module ProductVariant
|
4
|
+
include Radiant::Taggable
|
5
|
+
|
6
|
+
tag 'shop:product:variants' do |tag|
|
7
|
+
tag.locals.shop_product_variants = Helpers.current_product_variants(tag)
|
8
|
+
|
9
|
+
tag.expand
|
10
|
+
end
|
11
|
+
|
12
|
+
tag 'shop:product:variants:if_variants' do |tag|
|
13
|
+
tag.expand if tag.locals.shop_product_variants.present?
|
14
|
+
end
|
15
|
+
|
16
|
+
tag 'shop:product:variants:unless_variants' do |tag|
|
17
|
+
tag.expand if tag.locals.shop_product_variants.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
tag 'shop:product:variants:each' do |tag|
|
21
|
+
content = ''
|
22
|
+
|
23
|
+
tag.locals.shop_product_variants.each do |variant|
|
24
|
+
tag.locals.shop_product_variant = variant
|
25
|
+
content << tag.expand
|
26
|
+
end
|
27
|
+
|
28
|
+
content
|
29
|
+
end
|
30
|
+
|
31
|
+
tag 'shop:product:variant' do |tag|
|
32
|
+
tag.locals.shop_product_variant = Helpers.current_product_variant(tag)
|
33
|
+
tag.expand if tag.locals.shop_product_variant.present?
|
34
|
+
end
|
35
|
+
|
36
|
+
[:id, :name, :sku].each do |symbol|
|
37
|
+
desc %{ outputs the #{symbol} of the current shop variant }
|
38
|
+
tag "shop:product:variant:#{symbol}" do |tag|
|
39
|
+
tag.locals.shop_product_variant.send(symbol)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc %{ output price of variant }
|
44
|
+
tag 'shop:product:variant:price' do |tag|
|
45
|
+
attr = tag.attr.symbolize_keys
|
46
|
+
|
47
|
+
Shop::Tags::Helpers.currency(tag.locals.shop_product_variant.price,attr)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :shop_variants do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Shop Variants extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
ShopVariantsExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
ShopVariantsExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Shop Variants to the instance public/ directory."
|
18
|
+
task :update => :environment do
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
20
|
+
puts "Copying assets from ShopVariantsExtension"
|
21
|
+
Dir[ShopVariantsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(ShopVariantsExtension.root, '')
|
23
|
+
directory = File.dirname(path)
|
24
|
+
mkdir_p RAILS_ROOT + directory, :verbose => false
|
25
|
+
cp file, RAILS_ROOT + path, :verbose => false
|
26
|
+
end
|
27
|
+
unless ShopVariantsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
|
28
|
+
puts "Copying rake tasks from ShopVariantsExtension"
|
29
|
+
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
|
30
|
+
mkdir_p local_tasks_path, :verbose => false
|
31
|
+
Dir[File.join ShopVariantsExtension.root, %w(lib tasks *.rake)].each do |file|
|
32
|
+
cp file, local_tasks_path, :verbose => false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Syncs all available translations for this ext to the English ext master"
|
38
|
+
task :sync => :environment do
|
39
|
+
# The main translation root, basically where English is kept
|
40
|
+
language_root = ShopVariantsExtension.root + "/config/locales"
|
41
|
+
words = TranslationSupport.get_translation_keys(language_root)
|
42
|
+
|
43
|
+
Dir["#{language_root}/*.yml"].each do |filename|
|
44
|
+
next if filename.match('_available_tags')
|
45
|
+
basename = File.basename(filename, '.yml')
|
46
|
+
puts "Syncing #{basename}"
|
47
|
+
(comments, other) = TranslationSupport.read_file(filename, basename)
|
48
|
+
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
|
49
|
+
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
|
50
|
+
TranslationSupport.write_file(filename, basename, comments, other)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
document.observe("dom:loaded", function() {
|
2
|
+
shop_variant_edit = new ShopVariantEdit();
|
3
|
+
shop_variant_edit.initialize();
|
4
|
+
|
5
|
+
Event.addBehavior({
|
6
|
+
'#variants .delete:click' : function(e) { shop_variant_edit.variantRemove($(this).up('.variant')) }
|
7
|
+
})
|
8
|
+
});
|
9
|
+
|
10
|
+
var ShopVariantEdit = Class.create({
|
11
|
+
|
12
|
+
initialize: function() {
|
13
|
+
},
|
14
|
+
|
15
|
+
variantRemove: function(element) {
|
16
|
+
var variant_id = element.readAttribute('data-variant_id');
|
17
|
+
var route = shop.getRoute('admin_shop_product_variant_path', 'js', variant_id);
|
18
|
+
|
19
|
+
if(confirm('Are you Sure?')) {
|
20
|
+
showStatus('Removing Variant...');
|
21
|
+
element.hide();
|
22
|
+
|
23
|
+
new Ajax.Request(route, {
|
24
|
+
method: 'delete',
|
25
|
+
onSuccess: function(data) {
|
26
|
+
element.remove();
|
27
|
+
}.bind(element),
|
28
|
+
onFailure: function(data) {
|
29
|
+
element.show();
|
30
|
+
}.bind(element),
|
31
|
+
onComplete: function() {
|
32
|
+
hideStatus();
|
33
|
+
}
|
34
|
+
});
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
});
|
File without changes
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{radiant-shop_variants-extension}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dirk Kelly"]
|
12
|
+
s.date = %q{2010-11-10}
|
13
|
+
s.description = %q{RadiantShop: Create variants of products, with alternative prices}
|
14
|
+
s.email = %q{dk@dirkkelly.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"app/controllers/admin/shop/products/variant_templates_controller.rb",
|
24
|
+
"app/controllers/admin/shop/products/variants_controller.rb",
|
25
|
+
"app/controllers/admin/shop/variants_controller.rb",
|
26
|
+
"app/models/shop_product_variant.rb",
|
27
|
+
"app/models/shop_variant.rb",
|
28
|
+
"app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml",
|
29
|
+
"app/views/admin/shop/products/edit/buttons/_new_variant.html.haml",
|
30
|
+
"app/views/admin/shop/products/edit/parts/_variants.html.haml",
|
31
|
+
"app/views/admin/shop/products/edit/popups/_browse_templates.html.haml",
|
32
|
+
"app/views/admin/shop/products/edit/popups/_new_variant.html.haml",
|
33
|
+
"app/views/admin/shop/products/edit/shared/_variant.html.haml",
|
34
|
+
"app/views/admin/shop/products/index/buttons/_variants.html.haml",
|
35
|
+
"app/views/admin/shop/variants/edit.html.haml",
|
36
|
+
"app/views/admin/shop/variants/edit/_foot.html.haml",
|
37
|
+
"app/views/admin/shop/variants/edit/_form.html.haml",
|
38
|
+
"app/views/admin/shop/variants/edit/_head.html.haml",
|
39
|
+
"app/views/admin/shop/variants/edit/_inputs.html.haml",
|
40
|
+
"app/views/admin/shop/variants/edit/_meta.html.haml",
|
41
|
+
"app/views/admin/shop/variants/edit/_parts.html.haml",
|
42
|
+
"app/views/admin/shop/variants/edit/_popups.html.haml",
|
43
|
+
"app/views/admin/shop/variants/edit/inputs/_name.html.haml",
|
44
|
+
"app/views/admin/shop/variants/edit/inputs/_options.html.haml",
|
45
|
+
"app/views/admin/shop/variants/index.html.haml",
|
46
|
+
"app/views/admin/shop/variants/index/_foot.html.haml",
|
47
|
+
"app/views/admin/shop/variants/index/_head.html.haml",
|
48
|
+
"app/views/admin/shop/variants/index/_variant.html.haml",
|
49
|
+
"app/views/admin/shop/variants/index/buttons/_add_variant.html.haml",
|
50
|
+
"app/views/admin/shop/variants/index/buttons/_categories.html.haml",
|
51
|
+
"app/views/admin/shop/variants/new.html.haml",
|
52
|
+
"app/views/admin/shop/variants/remove.html.haml",
|
53
|
+
"config/locales/en.yml",
|
54
|
+
"config/routes.rb",
|
55
|
+
"cucumber.yml",
|
56
|
+
"db/migrate/20101015162238_setup_shop_variants.rb",
|
57
|
+
"features/support/env.rb",
|
58
|
+
"features/support/paths.rb",
|
59
|
+
"lib/shop_variants/controllers/products_controller.rb",
|
60
|
+
"lib/shop_variants/interface/variants.rb",
|
61
|
+
"lib/shop_variants/models/product.rb",
|
62
|
+
"lib/shop_variants/tags/helpers.rb",
|
63
|
+
"lib/shop_variants/tags/product_variant.rb",
|
64
|
+
"lib/tasks/shop_variants_extension_tasks.rake",
|
65
|
+
"public/javascripts/admin/extensions/shop/variants/edit.js",
|
66
|
+
"public/stylesheets/sass/admin/extensions/shop/variants/edit.sass",
|
67
|
+
"radiant-shop_variants-extension.gemspec",
|
68
|
+
"shop_variants_extension.rb",
|
69
|
+
"spec/controllers/admin/shop/products/variant_templates_controller_spec.rb",
|
70
|
+
"spec/controllers/admin/shop/products/variants_controller_spec.rb",
|
71
|
+
"spec/controllers/admin/shop/variants_controller_spec.rb",
|
72
|
+
"spec/datasets/shop_product_variants.rb",
|
73
|
+
"spec/datasets/shop_variants.rb",
|
74
|
+
"spec/lib/shop_variants/tags/helpers_spec.rb",
|
75
|
+
"spec/lib/shop_variants/tags/product_variant_spec.rb",
|
76
|
+
"spec/models/shop_product_spec.rb",
|
77
|
+
"spec/models/shop_product_variant_spec.rb",
|
78
|
+
"spec/models/shop_variant_spec.rb",
|
79
|
+
"spec/spec.opts",
|
80
|
+
"spec/spec_helper.rb"
|
81
|
+
]
|
82
|
+
s.homepage = %q{http://github.com/thefrontiergroup/shop_variants}
|
83
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
84
|
+
s.require_paths = ["lib"]
|
85
|
+
s.rubygems_version = %q{1.3.7}
|
86
|
+
s.summary = %q{Shop Variants Extension for Radiant CMS}
|
87
|
+
s.test_files = [
|
88
|
+
"spec/controllers/admin/shop/products/variant_templates_controller_spec.rb",
|
89
|
+
"spec/controllers/admin/shop/products/variants_controller_spec.rb",
|
90
|
+
"spec/controllers/admin/shop/variants_controller_spec.rb",
|
91
|
+
"spec/datasets/shop_product_variants.rb",
|
92
|
+
"spec/datasets/shop_variants.rb",
|
93
|
+
"spec/lib/shop_variants/tags/helpers_spec.rb",
|
94
|
+
"spec/lib/shop_variants/tags/product_variant_spec.rb",
|
95
|
+
"spec/models/shop_product_spec.rb",
|
96
|
+
"spec/models/shop_product_variant_spec.rb",
|
97
|
+
"spec/models/shop_variant_spec.rb",
|
98
|
+
"spec/spec_helper.rb"
|
99
|
+
]
|
100
|
+
|
101
|
+
if s.respond_to? :specification_version then
|
102
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
103
|
+
s.specification_version = 3
|
104
|
+
|
105
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
106
|
+
s.add_runtime_dependency(%q<radiant-shop-extension>, [">= 0"])
|
107
|
+
else
|
108
|
+
s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
|
109
|
+
end
|
110
|
+
else
|
111
|
+
s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
# require_dependency 'application_controller'
|
3
|
+
|
4
|
+
class ShopVariantsExtension < Radiant::Extension
|
5
|
+
version "1.0"
|
6
|
+
description "Describe your extension here"
|
7
|
+
url "http://yourwebsite.com/shop_variants"
|
8
|
+
|
9
|
+
def activate
|
10
|
+
unless defined? admin.variants
|
11
|
+
Radiant::AdminUI.send :include, ShopVariants::Interface::Variants
|
12
|
+
|
13
|
+
admin.variants = Radiant::AdminUI.load_default_shop_variants_regions
|
14
|
+
end
|
15
|
+
|
16
|
+
Admin::Shop::ProductsController.send :include, ShopVariants::Controllers::ProductsController
|
17
|
+
|
18
|
+
ShopProduct.send :include, ShopVariants::Models::Product
|
19
|
+
Page.send :include, ShopVariants::Tags::ProductVariant
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::Products::VariantTemplatesController do
|
4
|
+
|
5
|
+
dataset :users, :shop_variants, :shop_product_variants
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
login_as :admin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#create' do
|
12
|
+
before :each do
|
13
|
+
@product = shop_products(:crusty_bread)
|
14
|
+
@variant = shop_variants(:milk_states)
|
15
|
+
@initial_product_variants = @product.variants.all
|
16
|
+
end
|
17
|
+
context 'successfully created' do
|
18
|
+
before :each do
|
19
|
+
stub(ShopProduct).find.with_any_args { @product }
|
20
|
+
put :update, :product_id => @product.id, :id => @variant.id
|
21
|
+
end
|
22
|
+
it 'should add the variant templates to product' do
|
23
|
+
final_variants = @product.variants.all
|
24
|
+
final_variants.should_not == @initial_product_variants
|
25
|
+
|
26
|
+
names = final_variants.map(&:name)
|
27
|
+
@variant.options.each do |name|
|
28
|
+
names.include?(name).should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
it 'should redirect to edit product path' do
|
32
|
+
response.should redirect_to(edit_admin_shop_product_path(@product))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'could not create' do
|
36
|
+
before :each do
|
37
|
+
stub(ShopProduct).find.with_any_args { @product }
|
38
|
+
mock(@product).apply_variant_template(@variant) { false }
|
39
|
+
put :update, :product_id => @product.id, :id => @variant.id
|
40
|
+
end
|
41
|
+
it 'should not add the variant templates to product' do
|
42
|
+
@product.variants.all.should == @initial_product_variants
|
43
|
+
end
|
44
|
+
it 'should assign flash error' do
|
45
|
+
flash.now[:error].should_not be_nil
|
46
|
+
end
|
47
|
+
it 'should redirect to edit product path' do
|
48
|
+
response.should redirect_to(edit_admin_shop_product_path(@product))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::Products::VariantsController do
|
4
|
+
|
5
|
+
dataset :users, :shop_variants, :shop_product_variants
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
login_as :admin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#create' do
|
12
|
+
before :all do
|
13
|
+
@product = shop_products(:crusty_bread)
|
14
|
+
end
|
15
|
+
context 'successfully created' do
|
16
|
+
before :each do
|
17
|
+
mock.instance_of(ShopProductVariant).save! { true }
|
18
|
+
end
|
19
|
+
context 'html' do
|
20
|
+
before :each do
|
21
|
+
post :create, :product_id => @product.id, :shop_product_variant => { }
|
22
|
+
end
|
23
|
+
it 'should redirect to product path' do
|
24
|
+
response.should redirect_to(edit_admin_shop_product_path(@product))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'js' do
|
28
|
+
before :each do
|
29
|
+
post :create, :product_id => @product.id, :shop_product_variant => { }, :format => 'js'
|
30
|
+
end
|
31
|
+
it 'should render the partial' do
|
32
|
+
response.should render_template('/admin/shop/products/edit/shared/_variant')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context 'could not be created' do
|
37
|
+
before :each do
|
38
|
+
mock.instance_of(ShopProductVariant).save! { raise ActiveRecord::RecordNotSaved }
|
39
|
+
end
|
40
|
+
context 'html' do
|
41
|
+
before :each do
|
42
|
+
post :create, :product_id => @product.id, :shop_product_variant => { }
|
43
|
+
end
|
44
|
+
it 'should assign flash error' do
|
45
|
+
flash.now[:error].should_not be_nil
|
46
|
+
end
|
47
|
+
it 'should redirect to product path' do
|
48
|
+
response.should redirect_to(edit_admin_shop_product_path(@product))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'js' do
|
52
|
+
before :each do
|
53
|
+
post :create, :product_id => @product.id, :shop_product_variant => { }, :format => 'js'
|
54
|
+
end
|
55
|
+
it 'should not be success' do
|
56
|
+
response.should_not be_success
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#destroy' do
|
63
|
+
before :each do
|
64
|
+
@product = shop_products(:crusty_bread)
|
65
|
+
@product_variant = shop_product_variants(:mouldy_crusty_bread)
|
66
|
+
end
|
67
|
+
describe 'successfully destroyed' do
|
68
|
+
before :each do
|
69
|
+
mock(ShopProductVariant).find(@product_variant.id.to_s) { @product_variant }
|
70
|
+
stub(@product_variant).destroy { true }
|
71
|
+
end
|
72
|
+
context 'html' do
|
73
|
+
before :each do
|
74
|
+
delete :destroy, :product_id => @product.id, :id => @product_variant.id
|
75
|
+
end
|
76
|
+
it 'should redirect to product path' do
|
77
|
+
response.should redirect_to(edit_admin_shop_product_path(@product_variant.product))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context 'js' do
|
81
|
+
before :each do
|
82
|
+
delete :destroy, :product_id => @product.id, :id => @product_variant.id, :format => 'js'
|
83
|
+
end
|
84
|
+
it 'should render the partial' do
|
85
|
+
response.should be_success
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
describe 'could not be destroyed' do
|
90
|
+
before :each do
|
91
|
+
mock(ShopProductVariant).find(@product_variant.id.to_s) { @product_variant }
|
92
|
+
stub(@product_variant).destroy { false }
|
93
|
+
end
|
94
|
+
context 'html' do
|
95
|
+
before :each do
|
96
|
+
delete :destroy, :product_id => @product.id, :id => @product_variant.id
|
97
|
+
end
|
98
|
+
it 'should assign flash error' do
|
99
|
+
flash.now[:error].should_not be_nil
|
100
|
+
end
|
101
|
+
it 'should redirect to product path' do
|
102
|
+
response.should redirect_to(edit_admin_shop_product_path(@product_variant.product))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
context 'js' do
|
106
|
+
before :each do
|
107
|
+
delete :destroy, :product_id => @product.id, :id => @product_variant.id, :format => 'js'
|
108
|
+
end
|
109
|
+
it 'should not be success' do
|
110
|
+
response.should_not be_success
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::VariantsController do
|
4
|
+
|
5
|
+
dataset :users, :shop_variants
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
login_as :admin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#new' do
|
12
|
+
context 'instance variables' do
|
13
|
+
it 'should be assigned' do
|
14
|
+
get :new
|
15
|
+
|
16
|
+
assigns(:inputs).should === ['name','options']
|
17
|
+
assigns(:meta).should === []
|
18
|
+
assigns(:buttons).should === []
|
19
|
+
assigns(:parts).should === []
|
20
|
+
assigns(:popups).should === []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#edit' do
|
26
|
+
context 'instance variables' do
|
27
|
+
it 'should be assigned' do
|
28
|
+
get :edit, :id => shop_variants(:bread_states).id
|
29
|
+
|
30
|
+
assigns(:inputs).should === ['name','options']
|
31
|
+
assigns(:meta).should === []
|
32
|
+
assigns(:buttons).should === []
|
33
|
+
assigns(:parts).should === []
|
34
|
+
assigns(:popups).should === []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#create' do
|
40
|
+
context 'instance variables' do
|
41
|
+
it 'should be assigned' do
|
42
|
+
post :create, :shop_variant => {}
|
43
|
+
|
44
|
+
assigns(:inputs).should === ['name','options']
|
45
|
+
assigns(:meta).should === []
|
46
|
+
assigns(:buttons).should === []
|
47
|
+
assigns(:parts).should === []
|
48
|
+
assigns(:popups).should === []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#update' do
|
54
|
+
context 'instance variables' do
|
55
|
+
it 'should be assigned' do
|
56
|
+
put :update, :id => shop_variants(:bread_states).id, :shop_variant => {}
|
57
|
+
|
58
|
+
assigns(:inputs).should === ['name','options']
|
59
|
+
assigns(:meta).should === []
|
60
|
+
assigns(:buttons).should === []
|
61
|
+
assigns(:parts).should === []
|
62
|
+
assigns(:popups).should === []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ShopProductVariantsDataset < Dataset::Base
|
2
|
+
|
3
|
+
uses :shop_products
|
4
|
+
|
5
|
+
def load
|
6
|
+
create_record :shop_product_variants, :mouldy_crusty_bread,
|
7
|
+
:name => 'mouldy',
|
8
|
+
:price => -2.50,
|
9
|
+
:product => shop_products(:crusty_bread)
|
10
|
+
|
11
|
+
create_record :shop_product_variants, :fresh_crusty_bread,
|
12
|
+
:name => 'fresh',
|
13
|
+
:price => 2.50,
|
14
|
+
:product => shop_products(:crusty_bread)
|
15
|
+
|
16
|
+
create_record :shop_product_variants, :royal_soft_bread,
|
17
|
+
:name => 'royal',
|
18
|
+
:price => 2.50,
|
19
|
+
:product => shop_products(:soft_bread)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|