radiant-shop-extension 0.91.4 → 0.91.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/app/controllers/admin/shop/products/images_controller.rb +14 -20
- data/app/models/shop_category.rb +11 -0
- data/app/models/shop_product.rb +8 -5
- data/app/views/admin/shop/products/index/_product.html.haml +2 -2
- data/config/locales/en.yml +1 -118
- data/db/migrate/20101208121105_move_to_page_attachments.rb +33 -0
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +1 -1
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +1 -1
- data/radiant-shop-extension.gemspec +6 -10
- data/shop_extension.rb +0 -1
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +15 -32
- data/spec/datasets/shop_product_attachments.rb +2 -2
- data/spec/datasets/shop_products.rb +2 -2
- data/spec/lib/shop/tags/product_spec.rb +3 -3
- metadata +9 -13
- data/app/models/shop_product_attachment.rb +0 -35
- data/spec/lib/shop/models/image_spec.rb +0 -28
- data/spec/models/shop_product_attachment_spec.rb +0 -75
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.add_dependency 'fastercsv', '>= 1.5.3'
|
13
13
|
gem.add_dependency 'acts_as_list', '>= 0.1.2'
|
14
14
|
gem.add_dependency 'radiant-settings-extension', '>= 1.1.1'
|
15
|
-
gem.add_dependency 'radiant-images-extension', '>= 0.
|
15
|
+
gem.add_dependency 'radiant-images-extension', '>= 0.5.0'
|
16
16
|
gem.add_dependency 'radiant-forms-extension', '>= 3.2.6'
|
17
17
|
gem.add_dependency 'radiant-users-extension', '>= 0.0.2'
|
18
18
|
gem.add_dependency 'radiant-drag_order-extension','>= 0.3.9'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.91.
|
1
|
+
0.91.7
|
@@ -1,23 +1,21 @@
|
|
1
1
|
class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
2
2
|
|
3
|
-
model_class
|
3
|
+
model_class Attachment
|
4
4
|
|
5
5
|
# GET /admin/shop/products/1/images
|
6
6
|
# GET /admin/shop/products/1/images.js
|
7
7
|
# GET /admin/shop/products/1/images.json AJAX and HTML
|
8
8
|
#----------------------------------------------------------------------------
|
9
9
|
def index
|
10
|
-
error
|
11
|
-
attr_hash = ShopProductAttachment.params
|
10
|
+
error = 'This Product has no Images.'
|
12
11
|
|
13
12
|
@shop_product = ShopProduct.find(params[:product_id])
|
14
|
-
@shop_product_images = @shop_product.images
|
15
13
|
|
16
|
-
unless @
|
14
|
+
unless @shop_product.images.empty?
|
17
15
|
respond_to do |format|
|
18
16
|
format.html { redirect_to edit_admin_shop_product_path(@shop_product) }
|
19
|
-
format.js { render :partial => '/admin/shop/products/edit/shared/image', :collection => @
|
20
|
-
format.json { render :json => @
|
17
|
+
format.js { render :partial => '/admin/shop/products/edit/shared/image', :collection => @shop_product.images }
|
18
|
+
format.json { render :json => @shop_product.images.to_json }
|
21
19
|
end
|
22
20
|
else
|
23
21
|
respond_to do |format|
|
@@ -38,14 +36,12 @@ class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
|
38
36
|
def sort
|
39
37
|
notice = 'Successfully sorted Images.'
|
40
38
|
error = 'Could not sort Images.'
|
41
|
-
attr_hash = ShopProductAttachment.params
|
42
|
-
|
43
39
|
begin
|
44
40
|
@shop_product = ShopProduct.find(params[:product_id])
|
45
41
|
|
46
42
|
@images = CGI::parse(params[:attachments])['product_attachments[]']
|
47
43
|
@images.each_with_index do |id, index|
|
48
|
-
|
44
|
+
Attachment.find(id).update_attributes!({ :position => index+1 })
|
49
45
|
end
|
50
46
|
|
51
47
|
respond_to do |format|
|
@@ -53,7 +49,7 @@ class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
|
53
49
|
redirect_to edit_admin_shop_product_path(@shop_product)
|
54
50
|
}
|
55
51
|
format.js { render :partial => '/admin/shop/products/edit/shared/image', :collection => @shop_product.images }
|
56
|
-
format.json { render :json => @shop_product.images.to_json
|
52
|
+
format.json { render :json => @shop_product.images.to_json }
|
57
53
|
end
|
58
54
|
rescue
|
59
55
|
respond_to do |format|
|
@@ -72,9 +68,8 @@ class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
|
72
68
|
# POST /admin/shop/products/1/images.json AJAX and HTML
|
73
69
|
#----------------------------------------------------------------------------
|
74
70
|
def create
|
75
|
-
notice
|
76
|
-
error
|
77
|
-
attr_hash = ShopProductAttachment.params
|
71
|
+
notice = 'Successfully created Image.'
|
72
|
+
error = 'Unable to create Image.'
|
78
73
|
|
79
74
|
begin
|
80
75
|
@shop_product = ShopProduct.find(params[:product_id])
|
@@ -85,14 +80,14 @@ class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
|
85
80
|
@image = Image.find(params[:attachment][:image_id])
|
86
81
|
end
|
87
82
|
|
88
|
-
@
|
83
|
+
@attachment = Attachment.create!(:image => @image, :page => @shop_product.page)
|
89
84
|
|
90
85
|
respond_to do |format|
|
91
86
|
format.html {
|
92
87
|
redirect_to edit_admin_shop_product_path(@shop_product)
|
93
88
|
}
|
94
|
-
format.js { render :partial => '/admin/shop/products/edit/shared/image', :locals => { :image => @
|
95
|
-
format.json { render :json => @
|
89
|
+
format.js { render :partial => '/admin/shop/products/edit/shared/image', :locals => { :image => @attachment } }
|
90
|
+
format.json { render :json => @attachment.to_json }
|
96
91
|
end
|
97
92
|
rescue
|
98
93
|
respond_to do |format|
|
@@ -113,11 +108,10 @@ class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
|
113
108
|
def destroy
|
114
109
|
notice = 'Image deleted successfully.'
|
115
110
|
error = 'Unable to delete Image.'
|
116
|
-
|
117
111
|
begin
|
118
112
|
@shop_product = ShopProduct.find(params[:product_id])
|
119
|
-
@image = @
|
120
|
-
@
|
113
|
+
@image = @attachment.image
|
114
|
+
@attachment.destroy
|
121
115
|
|
122
116
|
respond_to do |format|
|
123
117
|
format.html {
|
data/app/models/shop_category.rb
CHANGED
@@ -8,6 +8,8 @@ class ShopCategory < ActiveRecord::Base
|
|
8
8
|
belongs_to :updated_by, :class_name => 'User'
|
9
9
|
belongs_to :product_layout, :class_name => 'Layout'
|
10
10
|
|
11
|
+
has_many :attachments, :through => :page
|
12
|
+
|
11
13
|
before_validation :assign_slug, :assign_breadcrumb, :assign_page_class_name
|
12
14
|
|
13
15
|
accepts_nested_attributes_for :page
|
@@ -40,6 +42,15 @@ class ShopCategory < ActiveRecord::Base
|
|
40
42
|
# Returns the url of the page
|
41
43
|
def url; page.url; end
|
42
44
|
|
45
|
+
# Return an array of the pages images
|
46
|
+
def images; page.images; end
|
47
|
+
|
48
|
+
# Returns an array of image ids
|
49
|
+
def image_ids; images.map(&:id); end
|
50
|
+
|
51
|
+
# Returns images not attached to category
|
52
|
+
def available_images; Image.all - images; end
|
53
|
+
|
43
54
|
# Returns the page slug
|
44
55
|
def slug; page.slug; end
|
45
56
|
|
data/app/models/shop_product.rb
CHANGED
@@ -6,15 +6,15 @@ class ShopProduct < ActiveRecord::Base
|
|
6
6
|
belongs_to :created_by, :class_name => 'User'
|
7
7
|
belongs_to :updated_by, :class_name => 'User'
|
8
8
|
|
9
|
-
has_many :line_items, :class_name => 'ShopLineItem',
|
10
|
-
has_many :orders, :class_name => 'ShopOrder',
|
11
|
-
|
12
|
-
has_many :
|
9
|
+
has_many :line_items, :class_name => 'ShopLineItem', :foreign_key => :item_id, :dependent => :destroy
|
10
|
+
has_many :orders, :class_name => 'ShopOrder', :through => :line_items, :uniq => true
|
11
|
+
|
12
|
+
has_many :attachments, :through => :page
|
13
13
|
|
14
14
|
before_validation :assign_slug, :assign_breadcrumb, :assign_page_class_name
|
15
15
|
validates_presence_of :page
|
16
16
|
|
17
|
-
validates_numericality_of :price,
|
17
|
+
validates_numericality_of :price, :greater_than => 0.00, :allow_nil => true, :precisions => 2
|
18
18
|
|
19
19
|
accepts_nested_attributes_for :page
|
20
20
|
|
@@ -48,6 +48,9 @@ class ShopProduct < ActiveRecord::Base
|
|
48
48
|
# Returns an array of customer ids
|
49
49
|
def customer_ids; customers.map(&:id); end
|
50
50
|
|
51
|
+
# Return an array of the pages images
|
52
|
+
def images; page.images; end
|
53
|
+
|
51
54
|
# Returns an array of image ids
|
52
55
|
def image_ids; images.map(&:id); end
|
53
56
|
|
@@ -5,8 +5,8 @@
|
|
5
5
|
%span.move.attribute
|
6
6
|
- body.icon do
|
7
7
|
- link_to [:edit_admin, product], :class => 'icon' do
|
8
|
-
- unless product.
|
9
|
-
= image_tag product.
|
8
|
+
- unless product.images.empty?
|
9
|
+
= image_tag product.images.first.url(:icon)
|
10
10
|
- body.name do
|
11
11
|
%span.name.attribute
|
12
12
|
- link_to [:edit_admin, product] do
|
data/config/locales/en.yml
CHANGED
@@ -63,121 +63,4 @@ en:
|
|
63
63
|
remove_product:
|
64
64
|
warning: "Deleting a product is irreversible, make sure you're sure."
|
65
65
|
remove_category:
|
66
|
-
warning: "Deleting a category (and its products) is irreversible, make sure you're sure."
|
67
|
-
en:
|
68
|
-
number:
|
69
|
-
# Used in number_with_delimiter()
|
70
|
-
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
71
|
-
format:
|
72
|
-
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
|
73
|
-
separator: "."
|
74
|
-
# Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
|
75
|
-
delimiter: ","
|
76
|
-
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
77
|
-
precision: 3
|
78
|
-
|
79
|
-
# Used in number_to_currency()
|
80
|
-
currency:
|
81
|
-
format:
|
82
|
-
# Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
|
83
|
-
format: "%u%n"
|
84
|
-
unit: "$"
|
85
|
-
# These three are to override number.format and are optional
|
86
|
-
separator: "."
|
87
|
-
delimiter: ","
|
88
|
-
precision: 2
|
89
|
-
|
90
|
-
# Used in number_to_percentage()
|
91
|
-
percentage:
|
92
|
-
format:
|
93
|
-
# These three are to override number.format and are optional
|
94
|
-
# separator:
|
95
|
-
delimiter: ""
|
96
|
-
# precision:
|
97
|
-
|
98
|
-
# Used in number_to_precision()
|
99
|
-
precision:
|
100
|
-
format:
|
101
|
-
# These three are to override number.format and are optional
|
102
|
-
# separator:
|
103
|
-
delimiter: ""
|
104
|
-
# precision:
|
105
|
-
|
106
|
-
# Used in number_to_human_size()
|
107
|
-
human:
|
108
|
-
format:
|
109
|
-
# These three are to override number.format and are optional
|
110
|
-
# separator:
|
111
|
-
delimiter: ""
|
112
|
-
precision: 1
|
113
|
-
storage_units:
|
114
|
-
# Storage units output formatting.
|
115
|
-
# %u is the storage unit, %n is the number (default: 2 MB)
|
116
|
-
format: "%n %u"
|
117
|
-
units:
|
118
|
-
byte:
|
119
|
-
one: "Byte"
|
120
|
-
other: "Bytes"
|
121
|
-
kb: "KB"
|
122
|
-
mb: "MB"
|
123
|
-
gb: "GB"
|
124
|
-
tb: "TB"
|
125
|
-
|
126
|
-
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
|
127
|
-
datetime:
|
128
|
-
distance_in_words:
|
129
|
-
half_a_minute: "half a minute"
|
130
|
-
less_than_x_seconds:
|
131
|
-
one: "less than 1 second"
|
132
|
-
other: "less than %{count} seconds"
|
133
|
-
x_seconds:
|
134
|
-
one: "1 second"
|
135
|
-
other: "%{count} seconds"
|
136
|
-
less_than_x_minutes:
|
137
|
-
one: "less than a minute"
|
138
|
-
other: "less than %{count} minutes"
|
139
|
-
x_minutes:
|
140
|
-
one: "1 minute"
|
141
|
-
other: "%{count} minutes"
|
142
|
-
about_x_hours:
|
143
|
-
one: "about 1 hour"
|
144
|
-
other: "about %{count} hours"
|
145
|
-
x_days:
|
146
|
-
one: "1 day"
|
147
|
-
other: "%{count} days"
|
148
|
-
about_x_months:
|
149
|
-
one: "about 1 month"
|
150
|
-
other: "about %{count} months"
|
151
|
-
x_months:
|
152
|
-
one: "1 month"
|
153
|
-
other: "%{count} months"
|
154
|
-
about_x_years:
|
155
|
-
one: "about 1 year"
|
156
|
-
other: "about %{count} years"
|
157
|
-
over_x_years:
|
158
|
-
one: "over 1 year"
|
159
|
-
other: "over %{count} years"
|
160
|
-
almost_x_years:
|
161
|
-
one: "almost 1 year"
|
162
|
-
other: "almost %{count} years"
|
163
|
-
prompts:
|
164
|
-
year: "Year"
|
165
|
-
month: "Month"
|
166
|
-
day: "Day"
|
167
|
-
hour: "Hour"
|
168
|
-
minute: "Minute"
|
169
|
-
second: "Seconds"
|
170
|
-
|
171
|
-
activerecord:
|
172
|
-
errors:
|
173
|
-
template:
|
174
|
-
header:
|
175
|
-
one: "1 error prohibited this %{model} from being saved"
|
176
|
-
other: "%{count} errors prohibited this %{model} from being saved"
|
177
|
-
# The variable :count is also available
|
178
|
-
body: "There were problems with the following fields:"
|
179
|
-
|
180
|
-
support:
|
181
|
-
select:
|
182
|
-
# default value for :prompt => true in FormOptionsHelper
|
183
|
-
prompt: "Please select"
|
66
|
+
warning: "Deleting a category (and its products) is irreversible, make sure you're sure."
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class ShopProductAttachment < ActiveRecord::Base
|
2
|
+
belongs_to :product, :class_name => 'ShopProduct'
|
3
|
+
belongs_to :image
|
4
|
+
end
|
5
|
+
|
6
|
+
class MoveToPageAttachments < ActiveRecord::Migration
|
7
|
+
def self.up
|
8
|
+
ShopProductAttachment.find_each do |a|
|
9
|
+
Attachment.create(:image => a.image, :page => a.product.page) rescue nil
|
10
|
+
end
|
11
|
+
drop_table :shop_product_attachments
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
create_table "shop_product_attachments", :force => true do |t|
|
16
|
+
t.integer "position", :default => 1
|
17
|
+
t.integer "image_id"
|
18
|
+
t.integer "product_id"
|
19
|
+
t.integer "created_by_id"
|
20
|
+
t.integer "updated_by_id"
|
21
|
+
end
|
22
|
+
add_index "shop_product_attachments", ["image_id"], :name => "index_shop_product_attachments_on_image_id"
|
23
|
+
add_index "shop_product_attachments", ["position"], :name => "index_shop_product_attachments_on_position"
|
24
|
+
add_index "shop_product_attachments", ["product_id"], :name => "index_shop_product_attachments_on_product_id"
|
25
|
+
|
26
|
+
Attachment.find_each do |a|
|
27
|
+
if a.page.shop_product
|
28
|
+
ShopProductAttachment.create(:image => a.image, :product => a.page.shop_product)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-shop-extension}
|
8
|
-
s.version = "0.91.
|
8
|
+
s.version = "0.91.7"
|
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", "John Barker", "Darcy Laycock"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-09}
|
13
13
|
s.description = %q{Radiant Shop is an attempt at a simple but complete store. It includes Products, Categories, Orders and Credit Card Payments}
|
14
14
|
s.email = %q{dk@dirkkelly.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,7 +43,6 @@ Gem::Specification.new do |s|
|
|
43
43
|
"app/models/shop_page.rb",
|
44
44
|
"app/models/shop_payment.rb",
|
45
45
|
"app/models/shop_product.rb",
|
46
|
-
"app/models/shop_product_attachment.rb",
|
47
46
|
"app/models/shop_product_page.rb",
|
48
47
|
"app/models/shop_shipping.rb",
|
49
48
|
"app/views/.DS_Store",
|
@@ -141,6 +140,7 @@ Gem::Specification.new do |s|
|
|
141
140
|
"config/routes.rb",
|
142
141
|
"db/migrate/20101011063133_setup_shop.rb",
|
143
142
|
"db/migrate/20101208045754_address_changes.rb",
|
143
|
+
"db/migrate/20101208121105_move_to_page_attachments.rb",
|
144
144
|
"db/seed.rb",
|
145
145
|
"db/seeds/forms.rb",
|
146
146
|
"db/seeds/layouts.rb",
|
@@ -197,7 +197,6 @@ Gem::Specification.new do |s|
|
|
197
197
|
"spec/datasets/shop_products.rb",
|
198
198
|
"spec/datasets/tags.rb",
|
199
199
|
"spec/helpers/nested_tag_helper.rb",
|
200
|
-
"spec/lib/shop/models/image_spec.rb",
|
201
200
|
"spec/lib/shop/models/page_spec.rb",
|
202
201
|
"spec/lib/shop/tags/address_spec.rb",
|
203
202
|
"spec/lib/shop/tags/card_spec.rb",
|
@@ -220,7 +219,6 @@ Gem::Specification.new do |s|
|
|
220
219
|
"spec/models/shop_line_item_spec.rb",
|
221
220
|
"spec/models/shop_order_spec.rb",
|
222
221
|
"spec/models/shop_payment_spec.rb",
|
223
|
-
"spec/models/shop_product_attachment_spec.rb",
|
224
222
|
"spec/models/shop_product_page_spec.rb",
|
225
223
|
"spec/models/shop_product_spec.rb",
|
226
224
|
"spec/models/shop_shipping_spec.rb",
|
@@ -250,7 +248,6 @@ Gem::Specification.new do |s|
|
|
250
248
|
"spec/datasets/shop_products.rb",
|
251
249
|
"spec/datasets/tags.rb",
|
252
250
|
"spec/helpers/nested_tag_helper.rb",
|
253
|
-
"spec/lib/shop/models/image_spec.rb",
|
254
251
|
"spec/lib/shop/models/page_spec.rb",
|
255
252
|
"spec/lib/shop/tags/address_spec.rb",
|
256
253
|
"spec/lib/shop/tags/card_spec.rb",
|
@@ -273,7 +270,6 @@ Gem::Specification.new do |s|
|
|
273
270
|
"spec/models/shop_line_item_spec.rb",
|
274
271
|
"spec/models/shop_order_spec.rb",
|
275
272
|
"spec/models/shop_payment_spec.rb",
|
276
|
-
"spec/models/shop_product_attachment_spec.rb",
|
277
273
|
"spec/models/shop_product_page_spec.rb",
|
278
274
|
"spec/models/shop_product_spec.rb",
|
279
275
|
"spec/models/shop_shipping_spec.rb",
|
@@ -290,7 +286,7 @@ Gem::Specification.new do |s|
|
|
290
286
|
s.add_runtime_dependency(%q<fastercsv>, [">= 1.5.3"])
|
291
287
|
s.add_runtime_dependency(%q<acts_as_list>, [">= 0.1.2"])
|
292
288
|
s.add_runtime_dependency(%q<radiant-settings-extension>, [">= 1.1.1"])
|
293
|
-
s.add_runtime_dependency(%q<radiant-images-extension>, [">= 0.
|
289
|
+
s.add_runtime_dependency(%q<radiant-images-extension>, [">= 0.5.0"])
|
294
290
|
s.add_runtime_dependency(%q<radiant-forms-extension>, [">= 3.2.6"])
|
295
291
|
s.add_runtime_dependency(%q<radiant-users-extension>, [">= 0.0.2"])
|
296
292
|
s.add_runtime_dependency(%q<radiant-drag_order-extension>, [">= 0.3.9"])
|
@@ -300,7 +296,7 @@ Gem::Specification.new do |s|
|
|
300
296
|
s.add_dependency(%q<fastercsv>, [">= 1.5.3"])
|
301
297
|
s.add_dependency(%q<acts_as_list>, [">= 0.1.2"])
|
302
298
|
s.add_dependency(%q<radiant-settings-extension>, [">= 1.1.1"])
|
303
|
-
s.add_dependency(%q<radiant-images-extension>, [">= 0.
|
299
|
+
s.add_dependency(%q<radiant-images-extension>, [">= 0.5.0"])
|
304
300
|
s.add_dependency(%q<radiant-forms-extension>, [">= 3.2.6"])
|
305
301
|
s.add_dependency(%q<radiant-users-extension>, [">= 0.0.2"])
|
306
302
|
s.add_dependency(%q<radiant-drag_order-extension>, [">= 0.3.9"])
|
@@ -311,7 +307,7 @@ Gem::Specification.new do |s|
|
|
311
307
|
s.add_dependency(%q<fastercsv>, [">= 1.5.3"])
|
312
308
|
s.add_dependency(%q<acts_as_list>, [">= 0.1.2"])
|
313
309
|
s.add_dependency(%q<radiant-settings-extension>, [">= 1.1.1"])
|
314
|
-
s.add_dependency(%q<radiant-images-extension>, [">= 0.
|
310
|
+
s.add_dependency(%q<radiant-images-extension>, [">= 0.5.0"])
|
315
311
|
s.add_dependency(%q<radiant-forms-extension>, [">= 3.2.6"])
|
316
312
|
s.add_dependency(%q<radiant-users-extension>, [">= 0.0.2"])
|
317
313
|
s.add_dependency(%q<radiant-drag_order-extension>, [">= 0.3.9"])
|
data/shop_extension.rb
CHANGED
@@ -16,7 +16,6 @@ class ShopExtension < Radiant::Extension
|
|
16
16
|
UserActionObserver.instance.send :add_observer!, ShopCategory
|
17
17
|
UserActionObserver.instance.send :add_observer!, ShopOrder
|
18
18
|
UserActionObserver.instance.send :add_observer!, ShopProduct
|
19
|
-
UserActionObserver.instance.send :add_observer!, ShopProductAttachment
|
20
19
|
|
21
20
|
def activate
|
22
21
|
tab "Shop" do
|
@@ -2,17 +2,15 @@ require File.dirname(__FILE__) + "/../../../../spec_helper"
|
|
2
2
|
|
3
3
|
describe Admin::Shop::Products::ImagesController do
|
4
4
|
|
5
|
-
dataset :users
|
5
|
+
dataset :users, :shop_products
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
login_as :admin
|
9
9
|
|
10
|
-
@shop_product =
|
11
|
-
|
12
|
-
mock(ShopProduct).find('1') { @shop_product }
|
10
|
+
@shop_product = shop_products(:soft_bread)
|
11
|
+
@images = @shop_product.images
|
13
12
|
|
14
|
-
@
|
15
|
-
@images = [ @image ]
|
13
|
+
mock(ShopProduct).find(@shop_product.id.to_s) { @shop_product }
|
16
14
|
end
|
17
15
|
|
18
16
|
describe '#index' do
|
@@ -60,10 +58,6 @@ describe Admin::Shop::Products::ImagesController do
|
|
60
58
|
response.should redirect_to(edit_admin_shop_product_path(@shop_product))
|
61
59
|
flash.now[:error].should be_nil
|
62
60
|
end
|
63
|
-
|
64
|
-
it 'should assign the shop_product_images instance variable' do
|
65
|
-
assigns(:shop_product_images).should === @images
|
66
|
-
end
|
67
61
|
end
|
68
62
|
|
69
63
|
context 'js' do
|
@@ -75,10 +69,6 @@ describe Admin::Shop::Products::ImagesController do
|
|
75
69
|
response.should be_success
|
76
70
|
response.should render_template('/admin/shop/products/edit/shared/_image')
|
77
71
|
end
|
78
|
-
|
79
|
-
it 'should assign the shop_product_images instance variable' do
|
80
|
-
assigns(:shop_product_images).should === @images
|
81
|
-
end
|
82
72
|
end
|
83
73
|
|
84
74
|
context 'json' do
|
@@ -88,11 +78,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
88
78
|
|
89
79
|
it 'should return a json object of the array and success status' do
|
90
80
|
response.should be_success
|
91
|
-
response.body.should === @images.to_json
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should assign the shop_product_images instance variable' do
|
95
|
-
assigns(:shop_product_images).should === @images
|
81
|
+
response.body.should === @images.to_json
|
96
82
|
end
|
97
83
|
end
|
98
84
|
end
|
@@ -141,8 +127,8 @@ describe Admin::Shop::Products::ImagesController do
|
|
141
127
|
|
142
128
|
context 'successfully sorted' do
|
143
129
|
before :each do
|
144
|
-
mock(
|
145
|
-
mock(
|
130
|
+
mock(Attachment).find('2').stub!.update_attributes!({:position => 1}) { true }
|
131
|
+
mock(Attachment).find('1').stub!.update_attributes!({:position => 2}) { true }
|
146
132
|
|
147
133
|
stub(@shop_product).images { @images }
|
148
134
|
end
|
@@ -185,7 +171,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
185
171
|
|
186
172
|
it 'should return a json object of the array and success status' do
|
187
173
|
response.should be_success
|
188
|
-
response.body.should == @images.to_json
|
174
|
+
response.body.should == @images.to_json
|
189
175
|
end
|
190
176
|
|
191
177
|
it 'should have ordered the images based on input' do
|
@@ -236,7 +222,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
236
222
|
|
237
223
|
context 'could not create attachment' do
|
238
224
|
before :each do
|
239
|
-
stub(
|
225
|
+
stub(Attachment).create!(anything) { raise ActiveRecord::RecordNotSaved }
|
240
226
|
end
|
241
227
|
|
242
228
|
context 'html' do
|
@@ -267,7 +253,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
267
253
|
context 'successfully created attachment' do
|
268
254
|
before :each do
|
269
255
|
@attachment = Object.new
|
270
|
-
|
256
|
+
mock(Attachment).create!(anything) { @attachment }
|
271
257
|
end
|
272
258
|
|
273
259
|
context 'html' do
|
@@ -281,7 +267,6 @@ describe Admin::Shop::Products::ImagesController do
|
|
281
267
|
it 'should render the collection partial and success status' do
|
282
268
|
post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'js'
|
283
269
|
response.should be_success
|
284
|
-
assigns(:shop_product_attachment).should == @attachment
|
285
270
|
response.should render_template('/admin/shop/products/edit/shared/_image')
|
286
271
|
end
|
287
272
|
end
|
@@ -290,7 +275,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
290
275
|
it 'should return a json object of the array and success status' do
|
291
276
|
post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'json'
|
292
277
|
response.should be_success
|
293
|
-
response.body.should == @attachment.to_json
|
278
|
+
response.body.should == @attachment.to_json
|
294
279
|
end
|
295
280
|
end
|
296
281
|
end
|
@@ -335,7 +320,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
335
320
|
|
336
321
|
context 'could not create attachment' do
|
337
322
|
before :each do
|
338
|
-
stub(
|
323
|
+
stub(Attachment).create!(anything) { raise ActiveRecord::RecordNotSaved }
|
339
324
|
end
|
340
325
|
|
341
326
|
context 'html' do
|
@@ -366,7 +351,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
366
351
|
context 'successfully created attachment' do
|
367
352
|
before :each do
|
368
353
|
@attachment = Object.new
|
369
|
-
stub(
|
354
|
+
stub(Attachment).create!(anything) { @attachment }
|
370
355
|
end
|
371
356
|
|
372
357
|
context 'html' do
|
@@ -380,7 +365,6 @@ describe Admin::Shop::Products::ImagesController do
|
|
380
365
|
it 'should render the collection partial and success status' do
|
381
366
|
post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'js'
|
382
367
|
response.should be_success
|
383
|
-
assigns(:shop_product_attachment).should === @attachment
|
384
368
|
response.should render_template('/admin/shop/products/edit/shared/_image')
|
385
369
|
end
|
386
370
|
end
|
@@ -389,7 +373,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
389
373
|
it 'should return a json object of the array and success status' do
|
390
374
|
post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'json'
|
391
375
|
response.should be_success
|
392
|
-
response.body.should == @attachment.to_json
|
376
|
+
response.body.should == @attachment.to_json
|
393
377
|
end
|
394
378
|
end
|
395
379
|
end
|
@@ -403,7 +387,7 @@ describe Admin::Shop::Products::ImagesController do
|
|
403
387
|
end
|
404
388
|
context 'Attachment exists' do
|
405
389
|
before :each do
|
406
|
-
mock(
|
390
|
+
mock(Attachment).find('1') { @image }
|
407
391
|
stub(@image).id { 1 }
|
408
392
|
end
|
409
393
|
context 'could not destroy attachment' do
|
@@ -453,7 +437,6 @@ describe Admin::Shop::Products::ImagesController do
|
|
453
437
|
it 'should render the collection partial and success status' do
|
454
438
|
delete :destroy, :id => @image.id, :product_id => @shop_product.id, :format => 'js'
|
455
439
|
response.should be_success
|
456
|
-
assigns(:shop_product_attachment).should == @image
|
457
440
|
response.should render_template('/admin/shop/products/edit/shared/_image')
|
458
441
|
end
|
459
442
|
end
|
@@ -12,9 +12,9 @@ class ShopProductAttachmentsDataset < Dataset::Base
|
|
12
12
|
:asset_content_type => "image/png",
|
13
13
|
:asset_file_size => i+1*1000
|
14
14
|
|
15
|
-
create_record :
|
15
|
+
create_record :attachment, image,
|
16
16
|
:image => images(image.to_sym),
|
17
|
-
:
|
17
|
+
:page => shop_products(image.to_s.split('_')[0,2].join('_').to_sym).page,
|
18
18
|
:position => i + 1
|
19
19
|
end
|
20
20
|
end
|
@@ -37,9 +37,9 @@ class ShopProductsDataset < Dataset::Base
|
|
37
37
|
:asset_content_type => 'image/png',
|
38
38
|
:asset_file_size => i + 1 * 10
|
39
39
|
|
40
|
-
create_record :
|
40
|
+
create_record :attachment, product,
|
41
41
|
:image => images(product),
|
42
|
-
:
|
42
|
+
:page => shop_products("#{product.to_s}_#{category.to_s}".to_sym).page,
|
43
43
|
:position => 1
|
44
44
|
end
|
45
45
|
end
|
@@ -279,7 +279,7 @@ describe Shop::Tags::Product do
|
|
279
279
|
end
|
280
280
|
context 'failure' do
|
281
281
|
it 'should not render' do
|
282
|
-
@product.images.delete_all
|
282
|
+
@product.page.images.delete_all
|
283
283
|
|
284
284
|
tag = %{<r:shop:product:images:if_images>failure</r:shop:product:images:if_images>}
|
285
285
|
exp = %{}
|
@@ -295,7 +295,7 @@ describe Shop::Tags::Product do
|
|
295
295
|
|
296
296
|
context 'success' do
|
297
297
|
it 'should render' do
|
298
|
-
@product.images.delete_all
|
298
|
+
@product.page.images.delete_all
|
299
299
|
|
300
300
|
tag = %{<r:shop:product:images:unless_images>success</r:shop:product:images:unless_images>}
|
301
301
|
exp = %{success}
|
@@ -338,7 +338,7 @@ describe Shop::Tags::Product do
|
|
338
338
|
end
|
339
339
|
context 'failure' do
|
340
340
|
it 'should not render' do
|
341
|
-
@product.images.delete_all
|
341
|
+
@product.page.images.delete_all
|
342
342
|
|
343
343
|
tag = %{<r:shop:product:images:each>failure</r:shop:product:images:each>}
|
344
344
|
exp = %{}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-shop-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 381
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 91
|
9
|
-
-
|
10
|
-
version: 0.91.
|
9
|
+
- 7
|
10
|
+
version: 0.91.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dirk Kelly
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-12-
|
20
|
+
date: 2010-12-09 00:00:00 +08:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -108,12 +108,12 @@ dependencies:
|
|
108
108
|
requirements:
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
hash:
|
111
|
+
hash: 11
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
-
|
115
|
-
-
|
116
|
-
version: 0.
|
114
|
+
- 5
|
115
|
+
- 0
|
116
|
+
version: 0.5.0
|
117
117
|
name: radiant-images-extension
|
118
118
|
requirement: *id006
|
119
119
|
- !ruby/object:Gem::Dependency
|
@@ -200,7 +200,6 @@ files:
|
|
200
200
|
- app/models/shop_page.rb
|
201
201
|
- app/models/shop_payment.rb
|
202
202
|
- app/models/shop_product.rb
|
203
|
-
- app/models/shop_product_attachment.rb
|
204
203
|
- app/models/shop_product_page.rb
|
205
204
|
- app/models/shop_shipping.rb
|
206
205
|
- app/views/.DS_Store
|
@@ -298,6 +297,7 @@ files:
|
|
298
297
|
- config/routes.rb
|
299
298
|
- db/migrate/20101011063133_setup_shop.rb
|
300
299
|
- db/migrate/20101208045754_address_changes.rb
|
300
|
+
- db/migrate/20101208121105_move_to_page_attachments.rb
|
301
301
|
- db/seed.rb
|
302
302
|
- db/seeds/forms.rb
|
303
303
|
- db/seeds/layouts.rb
|
@@ -354,7 +354,6 @@ files:
|
|
354
354
|
- spec/datasets/shop_products.rb
|
355
355
|
- spec/datasets/tags.rb
|
356
356
|
- spec/helpers/nested_tag_helper.rb
|
357
|
-
- spec/lib/shop/models/image_spec.rb
|
358
357
|
- spec/lib/shop/models/page_spec.rb
|
359
358
|
- spec/lib/shop/tags/address_spec.rb
|
360
359
|
- spec/lib/shop/tags/card_spec.rb
|
@@ -377,7 +376,6 @@ files:
|
|
377
376
|
- spec/models/shop_line_item_spec.rb
|
378
377
|
- spec/models/shop_order_spec.rb
|
379
378
|
- spec/models/shop_payment_spec.rb
|
380
|
-
- spec/models/shop_product_attachment_spec.rb
|
381
379
|
- spec/models/shop_product_page_spec.rb
|
382
380
|
- spec/models/shop_product_spec.rb
|
383
381
|
- spec/models/shop_shipping_spec.rb
|
@@ -436,7 +434,6 @@ test_files:
|
|
436
434
|
- spec/datasets/shop_products.rb
|
437
435
|
- spec/datasets/tags.rb
|
438
436
|
- spec/helpers/nested_tag_helper.rb
|
439
|
-
- spec/lib/shop/models/image_spec.rb
|
440
437
|
- spec/lib/shop/models/page_spec.rb
|
441
438
|
- spec/lib/shop/tags/address_spec.rb
|
442
439
|
- spec/lib/shop/tags/card_spec.rb
|
@@ -459,7 +456,6 @@ test_files:
|
|
459
456
|
- spec/models/shop_line_item_spec.rb
|
460
457
|
- spec/models/shop_order_spec.rb
|
461
458
|
- spec/models/shop_payment_spec.rb
|
462
|
-
- spec/models/shop_product_attachment_spec.rb
|
463
459
|
- spec/models/shop_product_page_spec.rb
|
464
460
|
- spec/models/shop_product_spec.rb
|
465
461
|
- spec/models/shop_shipping_spec.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'acts_as_list'
|
2
|
-
|
3
|
-
class ShopProductAttachment < ActiveRecord::Base
|
4
|
-
|
5
|
-
default_scope :order => 'shop_product_attachments.position ASC'
|
6
|
-
|
7
|
-
belongs_to :product, :class_name => 'ShopProduct'
|
8
|
-
belongs_to :image
|
9
|
-
|
10
|
-
belongs_to :created_by, :class_name => 'User'
|
11
|
-
belongs_to :updated_by, :class_name => 'User'
|
12
|
-
|
13
|
-
acts_as_list :scope => :product
|
14
|
-
|
15
|
-
def url(*params)
|
16
|
-
image.url(*params) rescue nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def title(*params)
|
20
|
-
image.title(*params) rescue nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def caption(*params)
|
24
|
-
image.caption(*params) rescue nil
|
25
|
-
end
|
26
|
-
|
27
|
-
class << self
|
28
|
-
|
29
|
-
def params
|
30
|
-
[ :id, :title, :caption, :image_file_name, :image_content_type, :image_file_size ]
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../../../spec_helper"
|
2
|
-
|
3
|
-
#
|
4
|
-
# Tests for image model extensions
|
5
|
-
#
|
6
|
-
describe Shop::Models::Image do
|
7
|
-
|
8
|
-
dataset :shop_products, :shop_product_attachments
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
@image = images(:soft_bread_front)
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'relationships' do
|
15
|
-
|
16
|
-
describe 'product' do
|
17
|
-
it 'should accept and return a product object' do
|
18
|
-
@shop_product = shop_products(:soft_bread)
|
19
|
-
|
20
|
-
@image.shop_products << @shop_product
|
21
|
-
|
22
|
-
@image.shop_products.include?(@shop_product).should === true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe ShopProductAttachment do
|
4
|
-
|
5
|
-
dataset :shop_products, :shop_product_attachments
|
6
|
-
|
7
|
-
context 'attributes' do
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@product_image = shop_products(:soft_bread).attachments.first
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should have a product id' do
|
14
|
-
@product_image.product.should === shop_products(:soft_bread)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should have an image id' do
|
18
|
-
@product_image.image.should === images(:soft_bread_front)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should have a position' do
|
22
|
-
@product_image.position.should === 1
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have a product' do
|
26
|
-
@product_image.product.class.should == ShopProduct
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should have an image' do
|
30
|
-
@product_image.image.class.should == Image
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'alias methods' do
|
36
|
-
|
37
|
-
before(:each) do
|
38
|
-
stub(AWS::S3::Base).establish_connection!
|
39
|
-
@product_image = shop_products(:soft_bread).attachments.first
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#url' do
|
43
|
-
it 'should return its assets url' do
|
44
|
-
stub(@product_image).image.stub!.url { 'url' }
|
45
|
-
@product_image.url.should === @product_image.image.url
|
46
|
-
end
|
47
|
-
end
|
48
|
-
describe '#title' do
|
49
|
-
it 'should return its assets title' do
|
50
|
-
@product_image.title.should === @product_image.image.title
|
51
|
-
end
|
52
|
-
end
|
53
|
-
describe '#caption' do
|
54
|
-
it 'should return its assets caption' do
|
55
|
-
@product_image.caption.should === @product_image.image.caption
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'class methods' do
|
61
|
-
describe '#params' do
|
62
|
-
it 'should have a set of standard parameters' do
|
63
|
-
ShopProductAttachment.params.should === [
|
64
|
-
:id,
|
65
|
-
:title,
|
66
|
-
:caption,
|
67
|
-
:image_file_name,
|
68
|
-
:image_content_type,
|
69
|
-
:image_file_size
|
70
|
-
]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|