radiant-shop_discounts-extension 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/README +3 -0
- data/Rakefile +138 -0
- data/VERSION +1 -0
- data/app/controllers/admin/shop/discounts/discountables_controller.rb +44 -0
- data/app/controllers/admin/shop/discounts_controller.rb +64 -0
- data/app/models/form_discount.rb +39 -0
- data/app/models/shop_discount.rb +37 -0
- data/app/models/shop_discountable.rb +64 -0
- data/app/views/admin/shop/discounts/edit.html.haml +11 -0
- data/app/views/admin/shop/discounts/edit/_foot.html.haml +16 -0
- data/app/views/admin/shop/discounts/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/discounts/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/discounts/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/discounts/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/discounts/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/discounts/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml +1 -0
- data/app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/discounts/edit/inputs/_amount.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/inputs/_code.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/meta/_finish.html.haml +5 -0
- data/app/views/admin/shop/discounts/edit/meta/_start.html.haml +5 -0
- data/app/views/admin/shop/discounts/edit/parts/_categories.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml +6 -0
- data/app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml +6 -0
- data/app/views/admin/shop/discounts/edit/shared/_category.html.haml +11 -0
- data/app/views/admin/shop/discounts/edit/shared/_product.html.haml +12 -0
- data/app/views/admin/shop/discounts/index.html.haml +13 -0
- data/app/views/admin/shop/discounts/index/_discount.html.haml +13 -0
- data/app/views/admin/shop/discounts/index/_foot.html.haml +5 -0
- data/app/views/admin/shop/discounts/index/_head.html.haml +2 -0
- data/app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml +1 -0
- data/app/views/admin/shop/discounts/new.html.haml +11 -0
- data/app/views/admin/shop/discounts/remove.html.haml +12 -0
- data/config/locales/en.yml +17 -0
- data/config/routes.rb +17 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20101015162137_setup_shop_discounts.rb +30 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop_discounts/models/discountable.rb +14 -0
- data/lib/shop_discounts/models/product.rb +20 -0
- data/lib/shop_discounts/models/purchaseable.rb +33 -0
- data/lib/shop_discounts/tags/cart.rb +18 -0
- data/lib/shop_discounts/tags/item.rb +30 -0
- data/lib/tasks/shop_discounts_extension_tasks.rake +55 -0
- data/public/javascripts/admin/extensions/shop/discounts/edit.js +76 -0
- data/public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass +125 -0
- data/radiant-shop_discounts-extension.gemspec +124 -0
- data/shop_discounts_extension.rb +31 -0
- data/spec/controllers/admin/shop/discounts/discountables_controller_spec.rb +72 -0
- data/spec/controllers/admin/shop/discounts_controller_spec.rb +81 -0
- data/spec/datasets/forms_discount.rb +24 -0
- data/spec/datasets/shop_discountables.rb +22 -0
- data/spec/datasets/shop_discounts.rb +34 -0
- data/spec/lib/shop_discounts/models/discountable_spec.rb +114 -0
- data/spec/lib/shop_discounts/models/purchaseable_spec.rb +55 -0
- data/spec/lib/shop_discounts/tags/item_spec.rb +96 -0
- data/spec/models/form_discount_spec.rb +63 -0
- data/spec/models/shop_category_spec.rb +19 -0
- data/spec/models/shop_discount_spec.rb +130 -0
- data/spec/models/shop_line_item_spec.rb +15 -0
- data/spec/models/shop_product_spec.rb +40 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +23 -0
- metadata +161 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
/* <li
|
2
|
+
class="discountable product" || class="discountable discounted"
|
3
|
+
id="product_1"
|
4
|
+
data-discounted_type_human="Product"
|
5
|
+
data-discounted_id="1"
|
6
|
+
data-discounted_type="ShopProduct"
|
7
|
+
data-success_element="discount_products"
|
8
|
+
/>
|
9
|
+
*/
|
10
|
+
|
11
|
+
document.observe("dom:loaded", function() {
|
12
|
+
shop_discount_edit = new ShopDiscountEdit();
|
13
|
+
shop_discount_edit.initialize();
|
14
|
+
|
15
|
+
Event.addBehavior({
|
16
|
+
'.discountable.available:click': function(e) { shop_discount_edit.discountedAttach($(this)) },
|
17
|
+
'.discountable.discounted .delete:click': function(e) { shop_discount_edit.discountedRemove($(this)) },
|
18
|
+
})
|
19
|
+
});
|
20
|
+
|
21
|
+
var ShopDiscountEdit = Class.create({
|
22
|
+
|
23
|
+
initialize: function() {
|
24
|
+
},
|
25
|
+
|
26
|
+
discountedAttach: function(element) {
|
27
|
+
var route = shop.getRoute('admin_shop_discount_discountables_path');
|
28
|
+
|
29
|
+
showStatus('Adding '+element.getAttribute('data-discounted_type_human')+'...');
|
30
|
+
new Ajax.Request(route, {
|
31
|
+
method: 'post',
|
32
|
+
parameters: {
|
33
|
+
'discounted_id': element.getAttribute('data-discounted_id'),
|
34
|
+
'discounted_type': element.getAttribute('data-discounted_type'),
|
35
|
+
},
|
36
|
+
onSuccess: function(data) {
|
37
|
+
$(element.getAttribute('data-success_element')).insert({ 'bottom' : data.responseText});
|
38
|
+
shop_discount_edit.postChanges(element);
|
39
|
+
}.bind(element),
|
40
|
+
onFailure: function() {
|
41
|
+
shop_discount_edit.errorStatus();
|
42
|
+
}
|
43
|
+
});
|
44
|
+
},
|
45
|
+
|
46
|
+
discountedRemove: function(element) {
|
47
|
+
var element = element.up('.discounted');
|
48
|
+
var discountable_id = element.readAttribute('data-discountable_id');
|
49
|
+
var route = shop.getRoute('admin_shop_discount_discountable_path', 'js', discountable_id);
|
50
|
+
|
51
|
+
showStatus('Removing '+element.getAttribute('data-discounted_type_human')+'...');
|
52
|
+
element.hide();
|
53
|
+
new Ajax.Request(route, {
|
54
|
+
method: 'delete',
|
55
|
+
onSuccess: function(data) {
|
56
|
+
$(element.getAttribute('data-success_element')).insert({ 'bottom' : data.responseText });
|
57
|
+
shop_discount_edit.postChanges(element);
|
58
|
+
},
|
59
|
+
onFailure: function(data) {
|
60
|
+
shop_discount_edit.errorStatus();
|
61
|
+
}
|
62
|
+
});
|
63
|
+
},
|
64
|
+
|
65
|
+
postChanges: function(element) {
|
66
|
+
element.remove();
|
67
|
+
|
68
|
+
hideStatus();
|
69
|
+
},
|
70
|
+
|
71
|
+
errorStatus: function() {
|
72
|
+
setStatus('Something went wrong, refreshing.');
|
73
|
+
location.reload(true);
|
74
|
+
}
|
75
|
+
|
76
|
+
});
|
@@ -0,0 +1,125 @@
|
|
1
|
+
ul.discounteds, .availables
|
2
|
+
padding:
|
3
|
+
top: 10px
|
4
|
+
|
5
|
+
li.discounted, .available
|
6
|
+
float: left
|
7
|
+
position: relative
|
8
|
+
padding: 10px
|
9
|
+
height: 100px
|
10
|
+
width: 100px
|
11
|
+
margin:
|
12
|
+
right: 10px
|
13
|
+
border:
|
14
|
+
radius: 6px
|
15
|
+
-moz:
|
16
|
+
border:
|
17
|
+
radius: 6px
|
18
|
+
-webkit:
|
19
|
+
border:
|
20
|
+
radius: 6px
|
21
|
+
cursor: move
|
22
|
+
overflow: hidden
|
23
|
+
*
|
24
|
+
vertical:
|
25
|
+
align: middle
|
26
|
+
|
27
|
+
.wrapper
|
28
|
+
display: table-cell
|
29
|
+
height: 100px
|
30
|
+
width: 100px
|
31
|
+
text:
|
32
|
+
align: center
|
33
|
+
vertical:
|
34
|
+
align: middle
|
35
|
+
|
36
|
+
img
|
37
|
+
width: 100px
|
38
|
+
max:
|
39
|
+
height: 100px
|
40
|
+
|
41
|
+
.name
|
42
|
+
line-height: 12px
|
43
|
+
font-size: 12px
|
44
|
+
position: absolute
|
45
|
+
display: block
|
46
|
+
width: 96%
|
47
|
+
top: 37.5px
|
48
|
+
left: 0
|
49
|
+
padding: 4px 2%
|
50
|
+
overflow: hidden
|
51
|
+
text-align: center
|
52
|
+
|
53
|
+
.sku, .handle
|
54
|
+
visibility: hidden
|
55
|
+
font-size: 10px
|
56
|
+
line-height: 12px
|
57
|
+
position: absolute
|
58
|
+
display: block
|
59
|
+
width: 96%
|
60
|
+
bottom: 12.5px
|
61
|
+
left: 0
|
62
|
+
padding: 4px 2%
|
63
|
+
overflow: hidden
|
64
|
+
text-align: center
|
65
|
+
color: #757575
|
66
|
+
|
67
|
+
&:hover
|
68
|
+
background:
|
69
|
+
color: #f9f6fe
|
70
|
+
|
71
|
+
.sku, .handle
|
72
|
+
visibility: visible
|
73
|
+
|
74
|
+
.name
|
75
|
+
background-color: #f9f6fe
|
76
|
+
|
77
|
+
ul.discounteds
|
78
|
+
overflow: hidden
|
79
|
+
|
80
|
+
li.discounted
|
81
|
+
|
82
|
+
.actions
|
83
|
+
position: absolute
|
84
|
+
display: block
|
85
|
+
width: 100%
|
86
|
+
top: 0
|
87
|
+
left: 0
|
88
|
+
|
89
|
+
.delete
|
90
|
+
position: absolute
|
91
|
+
top: 4px
|
92
|
+
right: -4px
|
93
|
+
width: 20px
|
94
|
+
height: 20px
|
95
|
+
overflow: hidden
|
96
|
+
display: block
|
97
|
+
cursor: pointer
|
98
|
+
background:
|
99
|
+
image: url('/images/admin/minus_disabled.png')
|
100
|
+
repeat: no-repeat
|
101
|
+
position: 0 0
|
102
|
+
cursor: pointer
|
103
|
+
|
104
|
+
&:hover
|
105
|
+
background:
|
106
|
+
image: url('/images/admin/minus.png')
|
107
|
+
|
108
|
+
ul.availables
|
109
|
+
/* This makes the scroll look nice */
|
110
|
+
margin:
|
111
|
+
right: -10px
|
112
|
+
top: -10px
|
113
|
+
padding:
|
114
|
+
left: 15px
|
115
|
+
bottom: 10px
|
116
|
+
width: 680px
|
117
|
+
max-height: 350px
|
118
|
+
overflow-y: scroll
|
119
|
+
|
120
|
+
li.available
|
121
|
+
|
122
|
+
.actions
|
123
|
+
|
124
|
+
.delete
|
125
|
+
display: none
|
@@ -0,0 +1,124 @@
|
|
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_discounts-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: Apply discounts to Products and Categories and have them accessed through codes}
|
14
|
+
s.email = %q{dk@dirkkelly.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".DS_Store",
|
20
|
+
".gitignore",
|
21
|
+
"README",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"app/controllers/admin/shop/discounts/discountables_controller.rb",
|
25
|
+
"app/controllers/admin/shop/discounts_controller.rb",
|
26
|
+
"app/models/form_discount.rb",
|
27
|
+
"app/models/shop_discount.rb",
|
28
|
+
"app/models/shop_discountable.rb",
|
29
|
+
"app/views/admin/shop/discounts/edit.html.haml",
|
30
|
+
"app/views/admin/shop/discounts/edit/_foot.html.haml",
|
31
|
+
"app/views/admin/shop/discounts/edit/_form.html.haml",
|
32
|
+
"app/views/admin/shop/discounts/edit/_head.html.haml",
|
33
|
+
"app/views/admin/shop/discounts/edit/_inputs.html.haml",
|
34
|
+
"app/views/admin/shop/discounts/edit/_meta.html.haml",
|
35
|
+
"app/views/admin/shop/discounts/edit/_parts.html.haml",
|
36
|
+
"app/views/admin/shop/discounts/edit/_popups.html.haml",
|
37
|
+
"app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml",
|
38
|
+
"app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml",
|
39
|
+
"app/views/admin/shop/discounts/edit/inputs/_amount.html.haml",
|
40
|
+
"app/views/admin/shop/discounts/edit/inputs/_code.html.haml",
|
41
|
+
"app/views/admin/shop/discounts/edit/inputs/_name.html.haml",
|
42
|
+
"app/views/admin/shop/discounts/edit/meta/_finish.html.haml",
|
43
|
+
"app/views/admin/shop/discounts/edit/meta/_start.html.haml",
|
44
|
+
"app/views/admin/shop/discounts/edit/parts/_categories.html.haml",
|
45
|
+
"app/views/admin/shop/discounts/edit/parts/_products.html.haml",
|
46
|
+
"app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml",
|
47
|
+
"app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml",
|
48
|
+
"app/views/admin/shop/discounts/edit/shared/_category.html.haml",
|
49
|
+
"app/views/admin/shop/discounts/edit/shared/_product.html.haml",
|
50
|
+
"app/views/admin/shop/discounts/index.html.haml",
|
51
|
+
"app/views/admin/shop/discounts/index/_discount.html.haml",
|
52
|
+
"app/views/admin/shop/discounts/index/_foot.html.haml",
|
53
|
+
"app/views/admin/shop/discounts/index/_head.html.haml",
|
54
|
+
"app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml",
|
55
|
+
"app/views/admin/shop/discounts/new.html.haml",
|
56
|
+
"app/views/admin/shop/discounts/remove.html.haml",
|
57
|
+
"config/locales/en.yml",
|
58
|
+
"config/routes.rb",
|
59
|
+
"cucumber.yml",
|
60
|
+
"db/migrate/20101015162137_setup_shop_discounts.rb",
|
61
|
+
"features/support/env.rb",
|
62
|
+
"features/support/paths.rb",
|
63
|
+
"lib/shop_discounts/models/discountable.rb",
|
64
|
+
"lib/shop_discounts/models/product.rb",
|
65
|
+
"lib/shop_discounts/models/purchaseable.rb",
|
66
|
+
"lib/shop_discounts/tags/cart.rb",
|
67
|
+
"lib/shop_discounts/tags/item.rb",
|
68
|
+
"lib/tasks/shop_discounts_extension_tasks.rake",
|
69
|
+
"public/javascripts/admin/extensions/shop/discounts/edit.js",
|
70
|
+
"public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass",
|
71
|
+
"radiant-shop_discounts-extension.gemspec",
|
72
|
+
"shop_discounts_extension.rb",
|
73
|
+
"spec/controllers/admin/shop/discounts/discountables_controller_spec.rb",
|
74
|
+
"spec/controllers/admin/shop/discounts_controller_spec.rb",
|
75
|
+
"spec/datasets/forms_discount.rb",
|
76
|
+
"spec/datasets/shop_discountables.rb",
|
77
|
+
"spec/datasets/shop_discounts.rb",
|
78
|
+
"spec/lib/shop_discounts/models/discountable_spec.rb",
|
79
|
+
"spec/lib/shop_discounts/models/purchaseable_spec.rb",
|
80
|
+
"spec/lib/shop_discounts/tags/item_spec.rb",
|
81
|
+
"spec/models/form_discount_spec.rb",
|
82
|
+
"spec/models/shop_category_spec.rb",
|
83
|
+
"spec/models/shop_discount_spec.rb",
|
84
|
+
"spec/models/shop_line_item_spec.rb",
|
85
|
+
"spec/models/shop_product_spec.rb",
|
86
|
+
"spec/spec.opts",
|
87
|
+
"spec/spec_helper.rb"
|
88
|
+
]
|
89
|
+
s.homepage = %q{http://github.com/thefrontiergroup/shop_discounts}
|
90
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
91
|
+
s.require_paths = ["lib"]
|
92
|
+
s.rubygems_version = %q{1.3.7}
|
93
|
+
s.summary = %q{Shop Discounts Extension for Radiant CMS}
|
94
|
+
s.test_files = [
|
95
|
+
"spec/controllers/admin/shop/discounts/discountables_controller_spec.rb",
|
96
|
+
"spec/controllers/admin/shop/discounts_controller_spec.rb",
|
97
|
+
"spec/datasets/forms_discount.rb",
|
98
|
+
"spec/datasets/shop_discountables.rb",
|
99
|
+
"spec/datasets/shop_discounts.rb",
|
100
|
+
"spec/lib/shop_discounts/models/discountable_spec.rb",
|
101
|
+
"spec/lib/shop_discounts/models/purchaseable_spec.rb",
|
102
|
+
"spec/lib/shop_discounts/tags/item_spec.rb",
|
103
|
+
"spec/models/form_discount_spec.rb",
|
104
|
+
"spec/models/shop_category_spec.rb",
|
105
|
+
"spec/models/shop_discount_spec.rb",
|
106
|
+
"spec/models/shop_line_item_spec.rb",
|
107
|
+
"spec/models/shop_product_spec.rb",
|
108
|
+
"spec/spec_helper.rb"
|
109
|
+
]
|
110
|
+
|
111
|
+
if s.respond_to? :specification_version then
|
112
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
113
|
+
s.specification_version = 3
|
114
|
+
|
115
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
116
|
+
s.add_runtime_dependency(%q<radiant-shop-extension>, [">= 0"])
|
117
|
+
else
|
118
|
+
s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
|
119
|
+
end
|
120
|
+
else
|
121
|
+
s.add_dependency(%q<radiant-shop-extension>, [">= 0"])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
# require_dependency 'application_controller'
|
3
|
+
|
4
|
+
class ShopDiscountsExtension < Radiant::Extension
|
5
|
+
version "1.0"
|
6
|
+
description "Describe your extension here"
|
7
|
+
url "http://yourwebsite.com/shop_discounts"
|
8
|
+
|
9
|
+
extension_config do |config|
|
10
|
+
#config.gem 'radiant-shop-extension', :lib => false
|
11
|
+
end
|
12
|
+
|
13
|
+
UserActionObserver.instance.send :add_observer!, ShopDiscount
|
14
|
+
UserActionObserver.instance.send :add_observer!, ShopDiscountable
|
15
|
+
|
16
|
+
def activate
|
17
|
+
|
18
|
+
tab "Shop" do
|
19
|
+
add_item "Discounts", "/admin/shop/discounts"
|
20
|
+
end
|
21
|
+
|
22
|
+
ShopLineItem.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::Purchaseable
|
23
|
+
|
24
|
+
ShopProduct.send :include, ShopDiscounts::Models::Discountable, ShopDiscounts::Models::Product
|
25
|
+
ShopOrder.send :include, ShopDiscounts::Models::Discountable
|
26
|
+
ShopCategory.send :include, ShopDiscounts::Models::Discountable
|
27
|
+
|
28
|
+
Page.send :include, ShopDiscounts::Tags::Cart, ShopDiscounts::Tags::Item
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::Discounts::DiscountablesController do
|
4
|
+
|
5
|
+
dataset :users, :shop_discountables
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
login_as :admin
|
9
|
+
@discountable = shop_discountables(:ten_percent_bread)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#create' do
|
13
|
+
before :each do
|
14
|
+
@discounted = shop_products(:warm_bread)
|
15
|
+
end
|
16
|
+
context 'packing could not be created' do
|
17
|
+
before :each do
|
18
|
+
stub(ShopDiscountable).new { @discountable }
|
19
|
+
mock(@discountable).save! { raise ActiveRecord::RecordNotSaved }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'js' do
|
23
|
+
it 'should return error notice and failure status' do
|
24
|
+
post :create, :discount_id => @discountable.discount.id, :discounted_id => @discounted.id, :discounted_type => @discounted.class.name, :format => 'js'
|
25
|
+
response.body.should === 'Could not attach Discount.'
|
26
|
+
response.should_not be_success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'packing successfully created' do
|
32
|
+
context 'js' do
|
33
|
+
it 'should render the collection partial and success status' do
|
34
|
+
post :create, :discount_id => @discountable.discount.id, :discounted_id => @discounted.id, :discounted_type => @discounted.class.name, :format => 'js'
|
35
|
+
|
36
|
+
response.should be_success
|
37
|
+
assigns(:shop_discountable).is_a?(ShopDiscountable).should === true
|
38
|
+
response.should render_template('admin/shop/discounts/edit/shared/_product')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#destroy' do
|
45
|
+
context 'discountable not destroyed' do
|
46
|
+
before :each do
|
47
|
+
stub(ShopDiscountable).find(@discountable.id.to_s) { @discountable }
|
48
|
+
stub(@discountable).destroy { raise ActiveRecord::RecordNotFound }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'js' do
|
52
|
+
it 'should render an error and failure status' do
|
53
|
+
delete :destroy, :discount_id => @discountable.discount.id, :id => @discountable.id, :format => 'js'
|
54
|
+
|
55
|
+
response.should_not be_success
|
56
|
+
response.body.should === 'Could not remove Discount.'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'discountable successfully destroyed' do
|
62
|
+
context 'js' do
|
63
|
+
it 'should render success message and success status' do
|
64
|
+
delete :destroy, :discount_id => @discountable.discount.id, :id => @discountable.id, :format => 'js'
|
65
|
+
response.should be_success
|
66
|
+
response.should render_template('admin/shop/discounts/edit/shared/_category')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::DiscountsController do
|
4
|
+
|
5
|
+
dataset :users, :shop_discounts
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
login_as :admin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'index' do
|
12
|
+
context 'instance variables' do
|
13
|
+
it 'should be assigned' do
|
14
|
+
get :index
|
15
|
+
|
16
|
+
assigns(:inputs).should === []
|
17
|
+
assigns(:meta).should === []
|
18
|
+
assigns(:buttons).should === ['new_discount']
|
19
|
+
assigns(:parts).should === []
|
20
|
+
assigns(:popups).should === []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#new' do
|
26
|
+
context 'instance variables' do
|
27
|
+
it 'should be assigned' do
|
28
|
+
get :new
|
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 === []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#edit' do
|
40
|
+
context 'instance variables' do
|
41
|
+
it 'should be assigned' do
|
42
|
+
get :edit, :id => shop_discounts(:ten_percent).id
|
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']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#create' do
|
54
|
+
context 'instance variables' do
|
55
|
+
it 'should be assigned' do
|
56
|
+
post :create, :shop_variant => {}
|
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 === []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#update' do
|
68
|
+
context 'instance variables' do
|
69
|
+
it 'should be assigned' do
|
70
|
+
put :update, :id => shop_discounts(:ten_percent).id, :shop_variant => {}
|
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']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|