spree 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree might be problematic. Click here for more details.
- data/CHANGELOG +35 -0
- data/CONTRIBUTORS +2 -1
- data/README.markdown +8 -52
- data/app/controllers/account_controller.rb +1 -1
- data/app/controllers/addresses_controller.rb +5 -1
- data/app/controllers/admin/inventory_settings_controller.rb +13 -0
- data/app/controllers/admin/option_types_controller.rb +1 -1
- data/app/controllers/admin/orders_controller.rb +14 -8
- data/app/controllers/admin/products_controller.rb +2 -0
- data/app/controllers/admin/variants_controller.rb +7 -0
- data/app/controllers/content_controller.rb +5 -0
- data/app/controllers/creditcard_payments_controller.rb +2 -2
- data/app/controllers/orders_controller.rb +18 -2
- data/app/helpers/admin/inventory_settings_helper.rb +5 -0
- data/app/helpers/admin/product_properties_helper.rb +10 -2
- data/app/helpers/products_helper.rb +2 -2
- data/app/models/address.rb +2 -2
- data/app/models/app_configuration.rb +1 -0
- data/app/models/creditcard_payment.rb +6 -14
- data/app/models/order.rb +6 -12
- data/app/models/order_filter.rb +1 -0
- data/app/models/product.rb +9 -0
- data/app/models/product_property.rb +1 -0
- data/app/models/property.rb +0 -1
- data/app/models/zone.rb +17 -3
- data/app/views/account/login.html.erb +2 -14
- data/app/views/admin/configurations/index.html.erb +4 -0
- data/app/views/admin/inventory_settings/edit.html.erb +18 -0
- data/app/views/admin/inventory_settings/show.html.erb +11 -0
- data/app/views/admin/orders/_address.html.erb +1 -1
- data/app/views/admin/orders/index.html.erb +5 -1
- data/app/views/admin/orders/show.html.erb +3 -3
- data/app/views/admin/product_properties/_product_property.html.erb +6 -3
- data/app/views/admin/products/_form.html.erb +9 -1
- data/app/views/admin/prototypes/select.rjs +3 -1
- data/app/views/admin/variants/_form.html.erb +6 -0
- data/app/views/admin/variants/index.html.erb +7 -1
- data/app/views/creditcard_payments/_form_credit_card.html.erb +1 -1
- data/app/views/creditcard_payments/new.html.erb +7 -2
- data/app/views/products/show.html.erb +8 -2
- data/app/views/shared/_login.html.erb +17 -0
- data/app/views/shared/_products.html.erb +1 -1
- data/app/views/users/_form.html.erb +1 -1
- data/app/views/users/new.html.erb +19 -8
- data/config/boot.rb +1 -1
- data/config/database.yml +7 -3
- data/config/environment.rb +16 -2
- data/config/routes.rb +4 -0
- data/db/migrate/20081016002224_remove_defunct_order_fields.rb +10 -0
- data/db/migrate/20081016162924_drop_category_id_from_products.rb +9 -0
- data/db/sample/addresses.yml +14 -0
- data/db/sample/orders.yml +0 -1
- data/lang/ui/de-DE.yml +2 -1
- data/lang/ui/en-US.yml +50 -25
- data/lang/ui/es-ES.yml +2 -1
- data/lang/ui/it-IT.yml +2 -1
- data/lang/ui/pl-PL.yml +1 -0
- data/lang/ui/pt-BR.yml +5 -2
- data/lib/authenticated_system.rb +1 -1
- data/lib/generators/extension/extension_generator.rb +1 -0
- data/lib/generators/extension/templates/extension.rb +4 -5
- data/lib/generators/extension/templates/tasks.rake +12 -0
- data/lib/generators/extension_migration/extension_migration_generator.rb +32 -0
- data/lib/generators/extension_migration/templates/migration.rb +7 -0
- data/lib/spree.rb +2 -2
- data/lib/spree/extension.rb +0 -7
- data/lib/spree/extension_loader.rb +0 -8
- data/lib/tasks/extensions.rake +47 -0
- data/public/javascripts/application.js +34 -0
- data/public/javascripts/spree-yui.js +2 -2
- data/public/stylesheets/spree.css +11 -1
- data/spec/fixtures/preferences.yml +14 -6
- data/spec/models/address_spec.rb +78 -0
- data/spec/models/country_spec.rb +29 -0
- data/spec/models/option_type_spec.rb +36 -0
- data/spec/models/option_value_spec.rb +39 -0
- data/spec/models/product_option_type_spec.rb +38 -0
- data/spec/models/product_property_spec.rb +36 -0
- data/spec/models/product_spec.rb +109 -32
- data/spec/models/property_spec.rb +38 -0
- data/spec/models/prototype_spec.rb +35 -0
- data/spec/models/state_spec.rb +28 -0
- data/spec/models/taxon_spec.rb +38 -0
- data/spec/models/taxonomy_spec.rb +37 -0
- data/spec/models/variant_spec.rb +73 -12
- data/spec/models/zone_spec.rb +35 -15
- data/spec/spec_helper.rb +15 -0
- data/spec/views/admin/configurations/index.html.erb_spec.rb +29 -0
- data/spec/views/admin/mail_settings/show.html.erb_spec.rb +3 -3
- data/spec/views/products/index.html.erb_spec.rb +46 -0
- data/spec/views/products/show.html.erb_spec.rb +46 -0
- data/vendor/extensions/flat_rate_shipping/README.markdown +3 -0
- data/vendor/extensions/flat_rate_shipping/Rakefile +120 -0
- data/vendor/extensions/flat_rate_shipping/flat_rate_shipping_extension.rb +17 -0
- data/vendor/extensions/flat_rate_shipping/lib/flat_rate_shipping_configuration.rb +7 -0
- data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/calculator.rb +9 -0
- data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/config.rb +22 -0
- data/vendor/extensions/flat_rate_shipping/lib/tasks/flat_rate_shipping_extension_tasks.rake +29 -0
- data/vendor/extensions/flat_rate_shipping/spec/spec.opts +6 -0
- data/vendor/extensions/flat_rate_shipping/spec/spec_helper.rb +37 -0
- data/vendor/extensions/localization/localization_extension.rb +1 -6
- data/vendor/extensions/payment_gateway/lib/gateway_config.rb +7 -0
- data/vendor/extensions/payment_gateway/lib/spree/gateway/config.rb +22 -0
- data/vendor/extensions/payment_gateway/lib/spree/payment_gateway.rb +27 -3
- data/vendor/extensions/payment_gateway/payment_gateway_extension.rb +0 -4
- data/vendor/extensions/shipping/README.markdown +3 -0
- data/vendor/extensions/shipping/Rakefile +120 -0
- data/vendor/extensions/shipping/app/controllers/admin/shipping_categories_controller.rb +17 -0
- data/vendor/extensions/shipping/app/controllers/admin/shipping_methods_controller.rb +21 -0
- data/vendor/extensions/shipping/app/controllers/shipments_controller.rb +84 -0
- data/vendor/extensions/shipping/app/helpers/admin/shipping_categories_helper.rb +2 -0
- data/vendor/extensions/shipping/app/helpers/admin/shipping_methods_helper.rb +2 -0
- data/vendor/extensions/shipping/app/helpers/shipments_helper.rb +20 -0
- data/vendor/extensions/shipping/app/models/shipment.rb +11 -0
- data/vendor/extensions/shipping/app/models/shipping_category.rb +3 -0
- data/vendor/extensions/shipping/app/models/shipping_method.rb +12 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_categories/_form.html.erb +6 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_categories/edit.html.erb +8 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_categories/index.html.erb +24 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_categories/new.html.erb +10 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_methods/_form.html.erb +14 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_methods/edit.html.erb +8 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_methods/index.html.erb +28 -0
- data/vendor/extensions/shipping/app/views/admin/shipping_methods/new.html.erb +10 -0
- data/vendor/extensions/shipping/app/views/orders/fatal_shipping.html.erb +6 -0
- data/vendor/extensions/shipping/app/views/shipments/_form.html.erb +46 -0
- data/vendor/extensions/shipping/app/views/shipments/edit.html.erb +8 -0
- data/vendor/extensions/shipping/app/views/shipments/new.html.erb +8 -0
- data/vendor/extensions/shipping/db/migrate/20081003211336_create_shipping_methods.rb +14 -0
- data/vendor/extensions/shipping/db/migrate/20081003233427_create_shipping_categories.rb +15 -0
- data/vendor/extensions/shipping/db/migrate/20081015001711_create_shipments.rb +14 -0
- data/vendor/extensions/shipping/db/migrate/20081023134446_add_product_dimensions.rb +19 -0
- data/vendor/extensions/shipping/db/sample/shipping_categories.yml +2 -0
- data/vendor/extensions/shipping/db/sample/shipping_methods.yml +12 -0
- data/vendor/extensions/shipping/db/sample/zone_members.yml +8 -0
- data/vendor/extensions/shipping/db/sample/zones.yml +3 -0
- data/vendor/extensions/shipping/lang/en-US.yml +9 -0
- data/vendor/extensions/shipping/lib/spree/shipping_calculator.rb +37 -0
- data/vendor/extensions/shipping/lib/spree/shipping_error.rb +3 -0
- data/vendor/extensions/shipping/lib/tasks/shipping_extension_tasks.rake +29 -0
- data/vendor/extensions/shipping/shipping_extension.rb +39 -0
- data/vendor/extensions/shipping/spec/controllers/admin/shipping_categories_controller_spec.rb +10 -0
- data/vendor/extensions/shipping/spec/controllers/admin/shipping_methods_controller_spec.rb +10 -0
- data/vendor/extensions/shipping/spec/models/order_spec.rb +98 -0
- data/vendor/extensions/shipping/spec/models/shipment_spec.rb +26 -0
- data/vendor/extensions/shipping/spec/models/shipping_category_spec.rb +8 -0
- data/vendor/extensions/shipping/spec/models/shipping_method_spec.rb +53 -0
- data/vendor/extensions/shipping/spec/spec.opts +6 -0
- data/vendor/extensions/shipping/spec/spec_helper.rb +37 -0
- data/vendor/extensions/tax_calculator/lib/spree/sales_tax_calculator.rb +12 -4
- data/vendor/extensions/tax_calculator/spec/controllers/tax_calculator_spec.rb +0 -4
- data/vendor/extensions/tax_calculator/spec/models/sales_tax_calculator_spec.rb +14 -14
- data/vendor/extensions/tax_calculator/tax_calculator_extension.rb +0 -4
- data/vendor/plugins/resource_controller/README.rdoc +38 -6
- data/vendor/plugins/resource_controller/Rakefile +7 -20
- data/vendor/plugins/resource_controller/TODO +0 -1
- data/vendor/plugins/resource_controller/lib/resource_controller/helpers/current_objects.rb +71 -69
- data/vendor/plugins/resource_controller/lib/resource_controller/helpers/internal.rb +69 -65
- data/vendor/plugins/resource_controller/lib/resource_controller/helpers/nested.rb +62 -57
- data/vendor/plugins/resource_controller/lib/resource_controller/helpers/singleton_customizations.rb +50 -46
- data/vendor/plugins/resource_controller/lib/resource_controller/helpers/urls.rb +73 -69
- data/vendor/plugins/resource_controller/resource_controller.gemspec +4 -3
- data/vendor/plugins/resource_controller/test/app/controllers/cms/personnel_controller.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/controllers/cms/photos_controller.rb +6 -0
- data/vendor/plugins/resource_controller/test/app/models/personnel.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/photo.rb +1 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/config/database.yml +9 -0
- data/vendor/plugins/resource_controller/test/config/environment.rb +1 -18
- data/vendor/plugins/resource_controller/test/config/initializers/inflections.rb +14 -0
- data/vendor/plugins/resource_controller/test/config/routes.rb +3 -0
- data/vendor/plugins/resource_controller/test/db/migrate/013_create_personnel.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/personnel.yml +5 -0
- data/vendor/plugins/resource_controller/test/test/functional/cms/photos_controller_test.rb +43 -0
- metadata +136 -6
- data/app/models/spree/extension_meta.rb +0 -5
- data/app/models/variants.rb +0 -2
- data/vendor/plugins/resource_controller/lib/resource_controller/version.rb +0 -9
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module ProductPropertySpecHelper
|
4
|
+
def valid_product_property_attributes
|
5
|
+
{
|
6
|
+
:value => "x"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
describe ProductProperty do
|
13
|
+
include ProductPropertySpecHelper
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@product_property = ProductProperty.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not be valid when empty" do
|
20
|
+
@product_property.should_not be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
['value'].each do |field|
|
24
|
+
it "should require #{field}" do
|
25
|
+
@product_property.should_not be_valid
|
26
|
+
@product_property.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be valid when having correct information" do
|
31
|
+
pending "Shouldn't it require a product and a property too?"
|
32
|
+
@product_property.attributes = valid_product_property_attributes
|
33
|
+
@product_property.should be_valid
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/models/product_spec.rb
CHANGED
@@ -1,18 +1,46 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module ProductSpecHelper
|
4
|
+
def valid_product_attributes
|
5
|
+
{
|
6
|
+
:name => "A Product",
|
7
|
+
:master_price => 10,
|
8
|
+
:description => "Just a test product."
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid_variant_attributes
|
13
|
+
{
|
14
|
+
:on_hand => 45,
|
15
|
+
:sku => "un"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
2
20
|
|
3
21
|
describe Product do
|
22
|
+
include ProductSpecHelper
|
4
23
|
|
5
24
|
before(:each) do
|
6
25
|
@product = Product.new
|
7
26
|
end
|
8
27
|
|
9
|
-
|
28
|
+
it "should not be valid when empty" do
|
29
|
+
@product.should_not be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
['name', 'master_price', 'description'].each do |field|
|
10
33
|
it "should require #{field}" do
|
11
|
-
@product.
|
12
|
-
@product.errors.full_messages.should include("#{field.
|
34
|
+
@product.should_not be_valid
|
35
|
+
@product.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
13
36
|
end
|
14
37
|
end
|
15
38
|
|
39
|
+
it "should be valid when having correct information" do
|
40
|
+
@product.attributes = valid_product_attributes
|
41
|
+
@product.should be_valid
|
42
|
+
end
|
43
|
+
|
16
44
|
describe "#variants?" do
|
17
45
|
it "should be false when variants is empty" do
|
18
46
|
@product.variants.should be_empty
|
@@ -20,17 +48,17 @@ describe Product do
|
|
20
48
|
end
|
21
49
|
|
22
50
|
it "should be false when none of the variants have option values" do
|
23
|
-
|
24
|
-
|
25
|
-
@product.variants <<
|
51
|
+
variant = mock_model(Variant)
|
52
|
+
variant.should_receive(:option_values).and_return([])
|
53
|
+
@product.variants << variant
|
26
54
|
@product.variants?.should be_false
|
27
55
|
end
|
28
56
|
|
29
57
|
it "should be true when at least one variant has option values" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@product.variants <<
|
58
|
+
option_value = mock_model(OptionValue)
|
59
|
+
variant = mock_model(Variant)
|
60
|
+
variant.should_receive(:option_values).and_return([option_value])
|
61
|
+
@product.variants << variant
|
34
62
|
@product.variants?.should be_true
|
35
63
|
end
|
36
64
|
end
|
@@ -39,20 +67,18 @@ describe Product do
|
|
39
67
|
it "should return the emtpy variant if there are only empty variant" do
|
40
68
|
variant = mock_model(Variant)
|
41
69
|
variant.stub!(:option_values).and_return([])
|
42
|
-
product
|
43
|
-
product.
|
44
|
-
product.variant.should == variant
|
70
|
+
@product.stub!(:variants).and_return([variant])
|
71
|
+
@product.variant.should == variant
|
45
72
|
end
|
46
73
|
|
47
74
|
it "should return nil if there are any non-empty variants" do
|
48
75
|
variant1 = mock_model(Variant)
|
49
76
|
variant1.stub!(:option_values).and_return([])
|
50
|
-
|
77
|
+
option_value = mock_model(OptionValue)
|
51
78
|
variant2 = mock_model(Variant)
|
52
|
-
variant2.stub!(:option_values).and_return([
|
53
|
-
product
|
54
|
-
product.
|
55
|
-
product.variant.should be_nil
|
79
|
+
variant2.stub!(:option_values).and_return([option_value])
|
80
|
+
@product.stub!(:variants).and_return([variant1, variant2])
|
81
|
+
@product.variant.should be_nil
|
56
82
|
end
|
57
83
|
end
|
58
84
|
|
@@ -74,11 +100,11 @@ describe Product do
|
|
74
100
|
|
75
101
|
describe "availability" do
|
76
102
|
before(:each) do
|
77
|
-
@product =
|
78
|
-
@
|
103
|
+
@product = Product.create(valid_product_attributes.with(:available_on => (Time.now - 1.day)))
|
104
|
+
@not_available_product = Product.create(valid_product_attributes.with(:available_on => (Time.now + 2.weeks)))
|
79
105
|
end
|
80
106
|
|
81
|
-
it "should only find
|
107
|
+
it "should only find available products using the available class method" do
|
82
108
|
Product.available.all.size.should eql(1)
|
83
109
|
end
|
84
110
|
|
@@ -91,15 +117,55 @@ describe Product do
|
|
91
117
|
describe 'inventory' do
|
92
118
|
|
93
119
|
before(:each) do
|
94
|
-
@variant =
|
95
|
-
@product =
|
120
|
+
@variant = Variant.create(valid_variant_attributes)
|
121
|
+
@product.attributes = valid_product_attributes
|
96
122
|
end
|
97
123
|
|
98
124
|
describe 'on_hand' do
|
99
125
|
it "should return the number of items available for the first variant" do
|
100
126
|
@product.stub!(:variant).and_return(@variant)
|
127
|
+
@variant.stub!(:on_hand).and_return(45)
|
101
128
|
@product.on_hand.should == 45
|
102
129
|
end
|
130
|
+
|
131
|
+
it "should update the inventory unit records of the corresponding variant when added" do
|
132
|
+
@product.save
|
133
|
+
@variant = Variant.create!({"price" => "10", "product" => @product})
|
134
|
+
|
135
|
+
@product.variant.inventory_units.size.should == 0
|
136
|
+
|
137
|
+
@product.update_attributes!({"on_hand" => "1"})
|
138
|
+
@product.variant.inventory_units.size.should == 1
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should update the inventory unit records of the corresponding variant when removed" do
|
142
|
+
@product.save
|
143
|
+
@variant = Variant.create!({"price" => "10", "product" => @product})
|
144
|
+
|
145
|
+
@product.variant.inventory_units.size.should == 0
|
146
|
+
|
147
|
+
@product.update_attributes!({"on_hand" => "2"})
|
148
|
+
@product.variant.inventory_units.size.should == 2
|
149
|
+
|
150
|
+
@product.update_attributes!({"on_hand" => "1"})
|
151
|
+
@product.variant.inventory_units.size.should == 1
|
152
|
+
|
153
|
+
@product.update_attributes!({"on_hand" => "0"})
|
154
|
+
@product.variant.inventory_units.size.should == 0
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'sku' do
|
159
|
+
it "should return the stock keeping unit for the first variant" do
|
160
|
+
@product.stub!(:variant).and_return(@variant)
|
161
|
+
@product.sku.should == "un"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should update the stock keeping unit of the corresponding variant when changed" do
|
165
|
+
@product.stub!(:variant).and_return(@variant)
|
166
|
+
@product.sku = "mt"
|
167
|
+
@variant.sku.should == "mt"
|
168
|
+
end
|
103
169
|
end
|
104
170
|
|
105
171
|
describe 'has_stock?' do
|
@@ -118,13 +184,24 @@ describe Product do
|
|
118
184
|
|
119
185
|
end
|
120
186
|
|
121
|
-
|
187
|
+
it "should update the inventory unit records of the corresponding variant with an initial value when created" do
|
188
|
+
@product.save
|
189
|
+
if @product.variants.empty?
|
190
|
+
@product.available_on = Time.now
|
191
|
+
@product.variants << Variant.new(:product => @product)
|
192
|
+
end
|
122
193
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
194
|
+
@product.update_attributes!(valid_product_attributes.with("on_hand" => "2"))
|
195
|
+
|
196
|
+
first_size = @product.variant.inventory_units.size
|
197
|
+
first_size.should == 2
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should update the empty variant if the 'master_price' attribute is changed" do
|
201
|
+
@variant = Variant.create(valid_variant_attributes)
|
202
|
+
@product.update_attributes!(valid_product_attributes)
|
203
|
+
@product.variants.stub!(:first).and_return(@variant)
|
204
|
+
@variant.should_receive(:price=).with(20)
|
205
|
+
@product.update_attributes!({"master_price" => "20"})
|
206
|
+
end
|
130
207
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module PropertySpecHelper
|
4
|
+
def valid_property_attributes
|
5
|
+
{
|
6
|
+
:name => "a_property",
|
7
|
+
:presentation => "A Property"
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
describe Property do
|
14
|
+
include PropertySpecHelper
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@property = Property.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not be valid when empty" do
|
21
|
+
@property.should_not be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
['name', 'presentation'].each do |field|
|
25
|
+
it "should require #{field}" do
|
26
|
+
@property.should_not be_valid
|
27
|
+
@property.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be valid when having correct information" do
|
32
|
+
@property.attributes = valid_property_attributes
|
33
|
+
@property.should be_valid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should find all by prototype"
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module PrototypeSpecHelper
|
4
|
+
def valid_prototype_attributes
|
5
|
+
{
|
6
|
+
:name => "A Prototype"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
describe Prototype do
|
13
|
+
include PrototypeSpecHelper
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@prototype = Prototype.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not be valid when empty" do
|
20
|
+
@prototype.should_not be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
['name'].each do |field|
|
24
|
+
it "should require #{field}" do
|
25
|
+
@prototype.should_not be_valid
|
26
|
+
@prototype.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be valid when having correct information" do
|
31
|
+
@prototype.attributes = valid_prototype_attributes
|
32
|
+
@prototype.should be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe State do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@state = State.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not be valid when empty" do
|
10
|
+
@state.should_not be_valid
|
11
|
+
end
|
12
|
+
|
13
|
+
['country', 'name'].each do |field|
|
14
|
+
it "should require #{field}" do
|
15
|
+
@state.should_not be_valid
|
16
|
+
@state.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be valid when having correct information" do
|
21
|
+
@state.name = "A State"
|
22
|
+
@state.abbr = "ST"
|
23
|
+
@state.country = Country.new
|
24
|
+
|
25
|
+
@state.should be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module TaxonHelper
|
4
|
+
def valid_taxon_attributes
|
5
|
+
{
|
6
|
+
:name => "A Taxon",
|
7
|
+
:position => 1
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Taxon do
|
13
|
+
include TaxonHelper
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@taxon = Taxon.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not be valid when empty" do
|
20
|
+
pending "Can it really be valid when empty?"
|
21
|
+
@taxon.should_not be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
['name'].each do |field|
|
25
|
+
it "should require #{field}" do
|
26
|
+
pending "Is this field mandatory?"
|
27
|
+
@taxon.should_not be_valid
|
28
|
+
@taxon.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be valid when having correct information" do
|
33
|
+
@taxon.attributes = valid_taxon_attributes
|
34
|
+
|
35
|
+
@taxon.should be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module TaxonomyHelper
|
4
|
+
def valid_taxonomy_attributes
|
5
|
+
{
|
6
|
+
:name => "A Taxonomy"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Taxonomy do
|
12
|
+
include TaxonomyHelper
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@taxonomy = Taxonomy.new
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not be valid when empty" do
|
19
|
+
pending "Can it really be valid when empty?"
|
20
|
+
@taxonomy.should_not be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
['name', 'root'].each do |field|
|
24
|
+
it "should require #{field}" do
|
25
|
+
pending "Is this field mandatory?"
|
26
|
+
@taxonomy.should_not be_valid
|
27
|
+
@taxonomy.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be valid when having correct information" do
|
32
|
+
@taxonomy.attributes = valid_taxonomy_attributes
|
33
|
+
|
34
|
+
@taxonomy.should be_valid
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/models/variant_spec.rb
CHANGED
@@ -1,14 +1,35 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module VariantSpecHelper
|
4
|
+
def valid_variant_attributes
|
5
|
+
{
|
6
|
+
:sku => "mt",
|
7
|
+
:price => 10,
|
8
|
+
:weight => 1,
|
9
|
+
:height => 1,
|
10
|
+
:width => 1,
|
11
|
+
:depth => 1
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
2
16
|
|
3
17
|
describe Variant do
|
4
|
-
|
5
|
-
|
18
|
+
include VariantSpecHelper
|
19
|
+
|
20
|
+
before(:each) do
|
6
21
|
@variant = Variant.new
|
7
22
|
end
|
8
23
|
|
9
|
-
it "should
|
10
|
-
@variant.
|
11
|
-
|
24
|
+
it "should not be valid when empty" do
|
25
|
+
@variant.should_not be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
['product'].each do |field|
|
29
|
+
it "should require #{field}" do
|
30
|
+
@variant.should_not be_valid
|
31
|
+
@variant.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
|
32
|
+
end
|
12
33
|
end
|
13
34
|
|
14
35
|
describe "with a valid product" do
|
@@ -18,20 +39,60 @@ describe Variant do
|
|
18
39
|
@variant.stub!(:product).and_return p
|
19
40
|
end
|
20
41
|
|
21
|
-
it "should be valid
|
22
|
-
@variant.
|
23
|
-
@variant.
|
42
|
+
it "should be valid when having correct information" do
|
43
|
+
@variant.attributes = valid_variant_attributes
|
44
|
+
@variant.should be_valid
|
24
45
|
end
|
25
|
-
|
26
|
-
it "should
|
46
|
+
|
47
|
+
it "should set the price with the same value as its product master_price if not set" do
|
27
48
|
@variant.product.should_receive(:master_price).exactly(2).and_return "11.33"
|
28
49
|
@variant.valid?.should be_true
|
29
50
|
@variant.price.should == BigDecimal.new("11.33")
|
30
51
|
end
|
31
52
|
|
32
|
-
it "should be
|
53
|
+
it "should not be valid if the price and its product master_price is not set" do
|
33
54
|
@variant.valid?.should be_false
|
34
55
|
@variant.errors.full_messages.should include("Must supply price for variant or master_price for product.")
|
35
56
|
end
|
57
|
+
|
58
|
+
describe 'on_hand' do
|
59
|
+
before do
|
60
|
+
@variant.update_attributes!(valid_variant_attributes)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should update the inventory unit records when added" do
|
64
|
+
@variant.inventory_units.size.should == 0
|
65
|
+
|
66
|
+
@variant.update_attributes!({"on_hand" => "1"})
|
67
|
+
@variant.inventory_units.size.should == 1
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should update the inventory unit records when removed" do
|
71
|
+
@variant.update_attributes!({"on_hand" => "2"})
|
72
|
+
@variant.inventory_units.size.should == 2
|
73
|
+
|
74
|
+
@variant.update_attributes!({"on_hand" => "1"})
|
75
|
+
@variant.inventory_units.size.should == 1
|
76
|
+
|
77
|
+
@variant.update_attributes!({"on_hand" => "0"})
|
78
|
+
@variant.inventory_units.size.should == 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return how many units are available when requested" do
|
83
|
+
@variant.update_attributes!(valid_variant_attributes)
|
84
|
+
@variant.on_hand.should == 0
|
85
|
+
|
86
|
+
@variant.update_attributes!({"on_hand" => 3.to_s})
|
87
|
+
@variant.on_hand.should == 3
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should respond if it is in stock" do
|
91
|
+
@variant.update_attributes!(valid_variant_attributes)
|
92
|
+
@variant.in_stock.should == false
|
93
|
+
|
94
|
+
@variant.update_attributes!({"on_hand" => 3.to_s})
|
95
|
+
@variant.in_stock.should == true
|
96
|
+
end
|
36
97
|
end
|
37
98
|
end
|