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.

Files changed (182) hide show
  1. data/CHANGELOG +35 -0
  2. data/CONTRIBUTORS +2 -1
  3. data/README.markdown +8 -52
  4. data/app/controllers/account_controller.rb +1 -1
  5. data/app/controllers/addresses_controller.rb +5 -1
  6. data/app/controllers/admin/inventory_settings_controller.rb +13 -0
  7. data/app/controllers/admin/option_types_controller.rb +1 -1
  8. data/app/controllers/admin/orders_controller.rb +14 -8
  9. data/app/controllers/admin/products_controller.rb +2 -0
  10. data/app/controllers/admin/variants_controller.rb +7 -0
  11. data/app/controllers/content_controller.rb +5 -0
  12. data/app/controllers/creditcard_payments_controller.rb +2 -2
  13. data/app/controllers/orders_controller.rb +18 -2
  14. data/app/helpers/admin/inventory_settings_helper.rb +5 -0
  15. data/app/helpers/admin/product_properties_helper.rb +10 -2
  16. data/app/helpers/products_helper.rb +2 -2
  17. data/app/models/address.rb +2 -2
  18. data/app/models/app_configuration.rb +1 -0
  19. data/app/models/creditcard_payment.rb +6 -14
  20. data/app/models/order.rb +6 -12
  21. data/app/models/order_filter.rb +1 -0
  22. data/app/models/product.rb +9 -0
  23. data/app/models/product_property.rb +1 -0
  24. data/app/models/property.rb +0 -1
  25. data/app/models/zone.rb +17 -3
  26. data/app/views/account/login.html.erb +2 -14
  27. data/app/views/admin/configurations/index.html.erb +4 -0
  28. data/app/views/admin/inventory_settings/edit.html.erb +18 -0
  29. data/app/views/admin/inventory_settings/show.html.erb +11 -0
  30. data/app/views/admin/orders/_address.html.erb +1 -1
  31. data/app/views/admin/orders/index.html.erb +5 -1
  32. data/app/views/admin/orders/show.html.erb +3 -3
  33. data/app/views/admin/product_properties/_product_property.html.erb +6 -3
  34. data/app/views/admin/products/_form.html.erb +9 -1
  35. data/app/views/admin/prototypes/select.rjs +3 -1
  36. data/app/views/admin/variants/_form.html.erb +6 -0
  37. data/app/views/admin/variants/index.html.erb +7 -1
  38. data/app/views/creditcard_payments/_form_credit_card.html.erb +1 -1
  39. data/app/views/creditcard_payments/new.html.erb +7 -2
  40. data/app/views/products/show.html.erb +8 -2
  41. data/app/views/shared/_login.html.erb +17 -0
  42. data/app/views/shared/_products.html.erb +1 -1
  43. data/app/views/users/_form.html.erb +1 -1
  44. data/app/views/users/new.html.erb +19 -8
  45. data/config/boot.rb +1 -1
  46. data/config/database.yml +7 -3
  47. data/config/environment.rb +16 -2
  48. data/config/routes.rb +4 -0
  49. data/db/migrate/20081016002224_remove_defunct_order_fields.rb +10 -0
  50. data/db/migrate/20081016162924_drop_category_id_from_products.rb +9 -0
  51. data/db/sample/addresses.yml +14 -0
  52. data/db/sample/orders.yml +0 -1
  53. data/lang/ui/de-DE.yml +2 -1
  54. data/lang/ui/en-US.yml +50 -25
  55. data/lang/ui/es-ES.yml +2 -1
  56. data/lang/ui/it-IT.yml +2 -1
  57. data/lang/ui/pl-PL.yml +1 -0
  58. data/lang/ui/pt-BR.yml +5 -2
  59. data/lib/authenticated_system.rb +1 -1
  60. data/lib/generators/extension/extension_generator.rb +1 -0
  61. data/lib/generators/extension/templates/extension.rb +4 -5
  62. data/lib/generators/extension/templates/tasks.rake +12 -0
  63. data/lib/generators/extension_migration/extension_migration_generator.rb +32 -0
  64. data/lib/generators/extension_migration/templates/migration.rb +7 -0
  65. data/lib/spree.rb +2 -2
  66. data/lib/spree/extension.rb +0 -7
  67. data/lib/spree/extension_loader.rb +0 -8
  68. data/lib/tasks/extensions.rake +47 -0
  69. data/public/javascripts/application.js +34 -0
  70. data/public/javascripts/spree-yui.js +2 -2
  71. data/public/stylesheets/spree.css +11 -1
  72. data/spec/fixtures/preferences.yml +14 -6
  73. data/spec/models/address_spec.rb +78 -0
  74. data/spec/models/country_spec.rb +29 -0
  75. data/spec/models/option_type_spec.rb +36 -0
  76. data/spec/models/option_value_spec.rb +39 -0
  77. data/spec/models/product_option_type_spec.rb +38 -0
  78. data/spec/models/product_property_spec.rb +36 -0
  79. data/spec/models/product_spec.rb +109 -32
  80. data/spec/models/property_spec.rb +38 -0
  81. data/spec/models/prototype_spec.rb +35 -0
  82. data/spec/models/state_spec.rb +28 -0
  83. data/spec/models/taxon_spec.rb +38 -0
  84. data/spec/models/taxonomy_spec.rb +37 -0
  85. data/spec/models/variant_spec.rb +73 -12
  86. data/spec/models/zone_spec.rb +35 -15
  87. data/spec/spec_helper.rb +15 -0
  88. data/spec/views/admin/configurations/index.html.erb_spec.rb +29 -0
  89. data/spec/views/admin/mail_settings/show.html.erb_spec.rb +3 -3
  90. data/spec/views/products/index.html.erb_spec.rb +46 -0
  91. data/spec/views/products/show.html.erb_spec.rb +46 -0
  92. data/vendor/extensions/flat_rate_shipping/README.markdown +3 -0
  93. data/vendor/extensions/flat_rate_shipping/Rakefile +120 -0
  94. data/vendor/extensions/flat_rate_shipping/flat_rate_shipping_extension.rb +17 -0
  95. data/vendor/extensions/flat_rate_shipping/lib/flat_rate_shipping_configuration.rb +7 -0
  96. data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/calculator.rb +9 -0
  97. data/vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/config.rb +22 -0
  98. data/vendor/extensions/flat_rate_shipping/lib/tasks/flat_rate_shipping_extension_tasks.rake +29 -0
  99. data/vendor/extensions/flat_rate_shipping/spec/spec.opts +6 -0
  100. data/vendor/extensions/flat_rate_shipping/spec/spec_helper.rb +37 -0
  101. data/vendor/extensions/localization/localization_extension.rb +1 -6
  102. data/vendor/extensions/payment_gateway/lib/gateway_config.rb +7 -0
  103. data/vendor/extensions/payment_gateway/lib/spree/gateway/config.rb +22 -0
  104. data/vendor/extensions/payment_gateway/lib/spree/payment_gateway.rb +27 -3
  105. data/vendor/extensions/payment_gateway/payment_gateway_extension.rb +0 -4
  106. data/vendor/extensions/shipping/README.markdown +3 -0
  107. data/vendor/extensions/shipping/Rakefile +120 -0
  108. data/vendor/extensions/shipping/app/controllers/admin/shipping_categories_controller.rb +17 -0
  109. data/vendor/extensions/shipping/app/controllers/admin/shipping_methods_controller.rb +21 -0
  110. data/vendor/extensions/shipping/app/controllers/shipments_controller.rb +84 -0
  111. data/vendor/extensions/shipping/app/helpers/admin/shipping_categories_helper.rb +2 -0
  112. data/vendor/extensions/shipping/app/helpers/admin/shipping_methods_helper.rb +2 -0
  113. data/vendor/extensions/shipping/app/helpers/shipments_helper.rb +20 -0
  114. data/vendor/extensions/shipping/app/models/shipment.rb +11 -0
  115. data/vendor/extensions/shipping/app/models/shipping_category.rb +3 -0
  116. data/vendor/extensions/shipping/app/models/shipping_method.rb +12 -0
  117. data/vendor/extensions/shipping/app/views/admin/shipping_categories/_form.html.erb +6 -0
  118. data/vendor/extensions/shipping/app/views/admin/shipping_categories/edit.html.erb +8 -0
  119. data/vendor/extensions/shipping/app/views/admin/shipping_categories/index.html.erb +24 -0
  120. data/vendor/extensions/shipping/app/views/admin/shipping_categories/new.html.erb +10 -0
  121. data/vendor/extensions/shipping/app/views/admin/shipping_methods/_form.html.erb +14 -0
  122. data/vendor/extensions/shipping/app/views/admin/shipping_methods/edit.html.erb +8 -0
  123. data/vendor/extensions/shipping/app/views/admin/shipping_methods/index.html.erb +28 -0
  124. data/vendor/extensions/shipping/app/views/admin/shipping_methods/new.html.erb +10 -0
  125. data/vendor/extensions/shipping/app/views/orders/fatal_shipping.html.erb +6 -0
  126. data/vendor/extensions/shipping/app/views/shipments/_form.html.erb +46 -0
  127. data/vendor/extensions/shipping/app/views/shipments/edit.html.erb +8 -0
  128. data/vendor/extensions/shipping/app/views/shipments/new.html.erb +8 -0
  129. data/vendor/extensions/shipping/db/migrate/20081003211336_create_shipping_methods.rb +14 -0
  130. data/vendor/extensions/shipping/db/migrate/20081003233427_create_shipping_categories.rb +15 -0
  131. data/vendor/extensions/shipping/db/migrate/20081015001711_create_shipments.rb +14 -0
  132. data/vendor/extensions/shipping/db/migrate/20081023134446_add_product_dimensions.rb +19 -0
  133. data/vendor/extensions/shipping/db/sample/shipping_categories.yml +2 -0
  134. data/vendor/extensions/shipping/db/sample/shipping_methods.yml +12 -0
  135. data/vendor/extensions/shipping/db/sample/zone_members.yml +8 -0
  136. data/vendor/extensions/shipping/db/sample/zones.yml +3 -0
  137. data/vendor/extensions/shipping/lang/en-US.yml +9 -0
  138. data/vendor/extensions/shipping/lib/spree/shipping_calculator.rb +37 -0
  139. data/vendor/extensions/shipping/lib/spree/shipping_error.rb +3 -0
  140. data/vendor/extensions/shipping/lib/tasks/shipping_extension_tasks.rake +29 -0
  141. data/vendor/extensions/shipping/shipping_extension.rb +39 -0
  142. data/vendor/extensions/shipping/spec/controllers/admin/shipping_categories_controller_spec.rb +10 -0
  143. data/vendor/extensions/shipping/spec/controllers/admin/shipping_methods_controller_spec.rb +10 -0
  144. data/vendor/extensions/shipping/spec/models/order_spec.rb +98 -0
  145. data/vendor/extensions/shipping/spec/models/shipment_spec.rb +26 -0
  146. data/vendor/extensions/shipping/spec/models/shipping_category_spec.rb +8 -0
  147. data/vendor/extensions/shipping/spec/models/shipping_method_spec.rb +53 -0
  148. data/vendor/extensions/shipping/spec/spec.opts +6 -0
  149. data/vendor/extensions/shipping/spec/spec_helper.rb +37 -0
  150. data/vendor/extensions/tax_calculator/lib/spree/sales_tax_calculator.rb +12 -4
  151. data/vendor/extensions/tax_calculator/spec/controllers/tax_calculator_spec.rb +0 -4
  152. data/vendor/extensions/tax_calculator/spec/models/sales_tax_calculator_spec.rb +14 -14
  153. data/vendor/extensions/tax_calculator/tax_calculator_extension.rb +0 -4
  154. data/vendor/plugins/resource_controller/README.rdoc +38 -6
  155. data/vendor/plugins/resource_controller/Rakefile +7 -20
  156. data/vendor/plugins/resource_controller/TODO +0 -1
  157. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/current_objects.rb +71 -69
  158. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/internal.rb +69 -65
  159. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/nested.rb +62 -57
  160. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/singleton_customizations.rb +50 -46
  161. data/vendor/plugins/resource_controller/lib/resource_controller/helpers/urls.rb +73 -69
  162. data/vendor/plugins/resource_controller/resource_controller.gemspec +4 -3
  163. data/vendor/plugins/resource_controller/test/app/controllers/cms/personnel_controller.rb +2 -0
  164. data/vendor/plugins/resource_controller/test/app/controllers/cms/photos_controller.rb +6 -0
  165. data/vendor/plugins/resource_controller/test/app/models/personnel.rb +3 -0
  166. data/vendor/plugins/resource_controller/test/app/models/photo.rb +1 -0
  167. data/vendor/plugins/resource_controller/test/app/views/cms/photos/edit.rhtml +17 -0
  168. data/vendor/plugins/resource_controller/test/app/views/cms/photos/index.rhtml +20 -0
  169. data/vendor/plugins/resource_controller/test/app/views/cms/photos/new.rhtml +16 -0
  170. data/vendor/plugins/resource_controller/test/app/views/cms/photos/show.rhtml +8 -0
  171. data/vendor/plugins/resource_controller/test/config/database.yml +9 -0
  172. data/vendor/plugins/resource_controller/test/config/environment.rb +1 -18
  173. data/vendor/plugins/resource_controller/test/config/initializers/inflections.rb +14 -0
  174. data/vendor/plugins/resource_controller/test/config/routes.rb +3 -0
  175. data/vendor/plugins/resource_controller/test/db/migrate/013_create_personnel.rb +11 -0
  176. data/vendor/plugins/resource_controller/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
  177. data/vendor/plugins/resource_controller/test/test/fixtures/personnel.yml +5 -0
  178. data/vendor/plugins/resource_controller/test/test/functional/cms/photos_controller_test.rb +43 -0
  179. metadata +136 -6
  180. data/app/models/spree/extension_meta.rb +0 -5
  181. data/app/models/variants.rb +0 -2
  182. data/vendor/plugins/resource_controller/lib/resource_controller/version.rb +0 -9
@@ -24,19 +24,19 @@ describe Zone do
24
24
  end
25
25
  end
26
26
 
27
- describe "#in_zone?" do
27
+ describe "#include?" do
28
28
  describe "with countries based zone" do
29
29
  it "should return true when the address country is included in the zones list of countries" do
30
30
  country = mock_model(Country)
31
31
  address = mock_model(Address, :country => country, :null_object => true)
32
32
  @zone.countries << country
33
- @zone.in_zone?(address).should be_true
33
+ @zone.include?(address).should be_true
34
34
  end
35
35
  it "should return false when the address country is not included in the zones list of countries " do
36
36
  country = mock_model(Country)
37
37
  address = mock_model(Address, :country => country, :null_object => true)
38
38
  @zone.countries << mock_model(Country)
39
- @zone.in_zone?(address).should be_false
39
+ @zone.include?(address).should be_false
40
40
  end
41
41
  end
42
42
  describe "with states based zone" do
@@ -44,29 +44,29 @@ describe Zone do
44
44
  state = mock_model(State)
45
45
  address = mock_model(Address, :state => state, :null_object => true)
46
46
  @zone.states << state
47
- @zone.in_zone?(address).should be_true
47
+ @zone.include?(address).should be_true
48
48
  end
49
49
  it "should return false when the address state is not included in the zones list of states" do
50
50
  state = mock_model(State)
51
51
  address = mock_model(Address, :state => state, :null_object => true)
52
52
  @zone.states << mock_model(State)
53
- @zone.in_zone?(address).should be_false
53
+ @zone.include?(address).should be_false
54
54
  end
55
55
  end
56
56
  describe "with zones based zone" do
57
57
  it "should return true when the address satisfies at least one of the zones in the list of zones" do
58
58
  address = mock_model(Address, :null_object => true)
59
59
  zone = mock_model(Zone)
60
- zone.should_receive(:in_zone?).with(address).and_return(true)
60
+ zone.should_receive(:include?).with(address).and_return(true)
61
61
  @zone.zones << zone
62
- @zone.in_zone?(address).should be_true
62
+ @zone.include?(address).should be_true
63
63
  end
64
64
  it "should return false when the address satisfies none of the zones in the list of zones" do
65
65
  address = mock_model(Address, :null_object => true)
66
66
  zone = mock_model(Zone)
67
- zone.should_receive(:in_zone?).with(address).and_return(false)
67
+ zone.should_receive(:include?).with(address).and_return(false)
68
68
  @zone.zones << zone
69
- @zone.in_zone?(address).should be_false
69
+ @zone.include?(address).should be_false
70
70
  end
71
71
  end
72
72
  end
@@ -84,30 +84,50 @@ describe Zone do
84
84
 
85
85
  it "should return only one zone if the address matches only one zone" do
86
86
  zone1 = mock_model(Zone)
87
- zone1.should_receive(:in_zone?).with(@address).and_return(true)
87
+ zone1.should_receive(:include?).with(@address).and_return(true)
88
88
  zone2 = mock_model(Zone)
89
- zone2.should_receive(:in_zone?).with(@address).and_return(false)
89
+ zone2.should_receive(:include?).with(@address).and_return(false)
90
90
  Zone.should_receive(:all).and_return([zone1, zone2])
91
91
  Zone.match(@address).should == [zone1]
92
92
  end
93
93
 
94
94
  it "should return both zones if the address matches both zones" do
95
95
  zone1 = mock_model(Zone)
96
- zone1.should_receive(:in_zone?).with(@address).and_return(true)
96
+ zone1.should_receive(:include?).with(@address).and_return(true)
97
97
  zone2 = mock_model(Zone)
98
- zone2.should_receive(:in_zone?).with(@address).and_return(true)
98
+ zone2.should_receive(:include?).with(@address).and_return(true)
99
99
  Zone.should_receive(:all).and_return([zone1, zone2])
100
100
  Zone.match(@address).should == [zone1, zone2]
101
101
  end
102
102
 
103
103
  it "should return no zones if address matches neither of the zones" do
104
104
  zone1 = mock_model(Zone)
105
- zone1.should_receive(:in_zone?).with(@address).and_return(false)
105
+ zone1.should_receive(:include?).with(@address).and_return(false)
106
106
  zone2 = mock_model(Zone)
107
- zone2.should_receive(:in_zone?).with(@address).and_return(false)
107
+ zone2.should_receive(:include?).with(@address).and_return(false)
108
108
  Zone.should_receive(:all).and_return([zone1, zone2])
109
109
  Zone.match(@address).should == []
110
110
  end
111
111
 
112
112
  end
113
+
114
+ describe "country_list" do
115
+ it "should return an empty array if the zone type is state" do
116
+ @zone.stub!(:type).and_return("state")
117
+ @zone.country_list.should == []
118
+ end
119
+ it "should return the corresponding countries if zone type is country" do
120
+ country = mock_model(Country)
121
+ @zone.should_receive(:countries).and_return([country])
122
+ @zone.country_list.should == [country]
123
+ end
124
+ it "should return the countries of the zone children if the type is zone" do
125
+ country1 = mock_model(Country)
126
+ country2 = mock_model(Country)
127
+ zone1 = mock_model(Zone, :country_list => [country1])
128
+ zone2 = mock_model(Zone, :country_list => [country2])
129
+ @zone.stub!(:members).and_return([zone1, zone2])
130
+ @zone.country_list.should == [country1, country2]
131
+ end
132
+ end
113
133
  end
data/spec/spec_helper.rb CHANGED
@@ -63,3 +63,18 @@ unless defined? SPEC_ROOT
63
63
  # for all of your examples, even those that don't use them.
64
64
  end
65
65
  end
66
+
67
+
68
+ class Hash
69
+ def except(*keys)
70
+ self.reject { |k,v| keys.include?(k || k.to_sym) }
71
+ end
72
+
73
+ def with(overrides = {})
74
+ self.merge overrides
75
+ end
76
+
77
+ def only(*keys)
78
+ self.reject { |k,v| !keys.include?(k || k.to_sym) }
79
+ end
80
+ end
@@ -1,8 +1,37 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
2
 
3
+ include PreferenceFactory
4
+
3
5
  describe "/admin/configurations" do
6
+
7
+
4
8
  before(:each) do
9
+ assigns[:extension_links] = []
5
10
  render 'admin/configurations/index'
6
11
  end
7
12
 
13
+ it "should display a Mail Server Settings link" do
14
+ response.should have_tag('a[href=?]', admin_mail_settings_path)
15
+ end
16
+
17
+ it "should display a Tax Categories link" do
18
+ response.should have_tag('a[href=?]', admin_tax_categories_path)
19
+ end
20
+
21
+ it "should display a Zones link" do
22
+ response.should have_tag('a[href=?]', admin_zones_path)
23
+ end
24
+
25
+ it "should display a States link" do
26
+ response.should have_tag('a[href=?]', admin_country_states_path(214))
27
+ end
28
+
29
+ it "should display a Gateway link" do
30
+ response.should have_tag('a[href=?]', admin_gateways_path)
31
+ end
32
+
33
+ it "should display an Inventory Settings link" do
34
+ response.should have_tag('a[href=?]', admin_inventory_settings_path)
35
+ end
36
+
8
37
  end
@@ -6,7 +6,7 @@ describe "/admin/configurations/:id/mail_settings" do
6
6
  end
7
7
 
8
8
  #Delete this example and add some real ones or delete this file
9
- # it "should have a div for mails settings" do
10
- # response.should have_tag('div#mail_settings')
11
- # end
9
+ it "should have a div for mails settings" do
10
+ response.should have_tag('div#mail_settings')
11
+ end
12
12
  end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/products/index' do
4
+ before(:each) do
5
+ @product = mock_model(Product)
6
+ template.stub!(:small_image)
7
+ template.stub!(:breadcrumbs).and_return("")
8
+ @product.stub!(:master_price)
9
+ @product.stub!(:name).and_return('Delicious Cows')
10
+ @product.stub!(:has_stock?).and_return(true)
11
+ assigns[:products] = [@product]
12
+
13
+ # TODO: put these pagination stubs into a helper?
14
+ assigns[:products].stub!(:page_count).and_return(1)
15
+ assigns[:products].stub!(:first_page).and_return(true)
16
+ assigns[:products].stub!(:previous_page?).and_return(false)
17
+ assigns[:products].stub!(:next_page?).and_return(false)
18
+ template.stub!(:windowed_pagination_links).and_return(false)
19
+ template.stub_render(:partial => 'shared/taxonomies')
20
+ end
21
+
22
+ it "should display items in stock" do
23
+ render '/products/index'
24
+ response.should have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
25
+ end
26
+
27
+ describe 'with out-of-stock items' do
28
+ before(:each) do
29
+ @product.stub!(:has_stock?).and_return(false)
30
+ end
31
+
32
+ it "should not display if show_zero_stock_products is not set" do
33
+ Spree::Config.stub!(:[]).with(:show_zero_stock_products).and_return(false)
34
+ render '/products/index'
35
+ response.should_not have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
36
+ end
37
+
38
+ it "should display if show_zero_stock_products is set" do
39
+ Spree::Config.stub!(:[]).with(:show_zero_stock_products).and_return(true)
40
+ render '/products/index'
41
+ response.should have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
42
+ end
43
+
44
+ end
45
+ end
46
+
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+
4
+ describe '/product/show' do
5
+ before(:each) do
6
+ template.stub!(:product_image)
7
+ @product = Product.new(:name => 'Delicious Cows', :permalink => 'delicious-cows',
8
+ :description => 'Cows are delicious!', :master_price => 45.00,
9
+ :variants => [Variant.new]
10
+ )
11
+ @product.stub!(:images).and_return(mock(Image, :size => 1))
12
+ assigns[:product] = @product
13
+ end
14
+
15
+ it "should display the item" do
16
+ render '/products/show'
17
+ response.should have_tag('td[class=?]', 'product-name', /#{@product.name}/)
18
+ end
19
+
20
+ describe 'with out-of-stock items' do
21
+ before(:each) do
22
+ @product.stub!(:has_stock?).and_return(false)
23
+ end
24
+
25
+ it "should not display product if allow_backorders is not set" do
26
+ Spree::Config.stub!(:[]).with(:allow_backorders).and_return(false)
27
+ render '/products/show'
28
+ response.should have_tag('strong', /Out of Stock/)
29
+ response.should_not have_tag('input[type=?]', 'submit')
30
+ end
31
+
32
+ it "should display product if allow_backorders is set" do
33
+ Spree::Config.stub!(:[]).with(:allow_backorders).and_return(true)
34
+ render '/products/show'
35
+ response.should_not have_tag('strong', /Out of Stock/)
36
+ response.should have_tag('input[type=?]', 'submit')
37
+ end
38
+ end
39
+
40
+ # NOTE: the behavior of variants is largely described thru the variant_options
41
+ # helper method in app/helpers/spree/base_helpers.rb. For that reason,
42
+ # the variant testing lives there
43
+
44
+ end
45
+
46
+
@@ -0,0 +1,3 @@
1
+ = Flat Rate Shipping
2
+
3
+ Description goes here
@@ -0,0 +1,120 @@
1
+ # I think this is the one that should be moved to the extension Rakefile template
2
+
3
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
4
+ # Check to see if the rspec plugin is installed first and require
5
+ # it if it is. If not, use the gem version.
6
+
7
+ # Determine where the RSpec plugin is by loading the boot
8
+ unless defined? SPREE_ROOT
9
+ ENV["RAILS_ENV"] = "test"
10
+ case
11
+ when ENV["SPREE_ENV_FILE"]
12
+ require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot"
13
+ when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
14
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
15
+ else
16
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
17
+ end
18
+ end
19
+
20
+ require 'rake'
21
+ require 'rake/rdoctask'
22
+ require 'rake/testtask'
23
+
24
+ rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib')
25
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
26
+ require 'spec/rake/spectask'
27
+ # require 'spec/translator'
28
+
29
+ # Cleanup the SPREE_ROOT constant so specs will load the environment
30
+ Object.send(:remove_const, :SPREE_ROOT)
31
+
32
+ extension_root = File.expand_path(File.dirname(__FILE__))
33
+
34
+ task :default => :spec
35
+ task :stats => "spec:statsetup"
36
+
37
+ desc "Run all specs in spec directory"
38
+ Spec::Rake::SpecTask.new(:spec) do |t|
39
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ namespace :spec do
44
+ desc "Run all specs in spec directory with RCov"
45
+ Spec::Rake::SpecTask.new(:rcov) do |t|
46
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
47
+ t.spec_files = FileList['spec/**/*_spec.rb']
48
+ t.rcov = true
49
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
50
+ end
51
+
52
+ desc "Print Specdoc for all specs"
53
+ Spec::Rake::SpecTask.new(:doc) do |t|
54
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ end
57
+
58
+ [:models, :controllers, :views, :helpers].each do |sub|
59
+ desc "Run the specs under spec/#{sub}"
60
+ Spec::Rake::SpecTask.new(sub) do |t|
61
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
62
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
63
+ end
64
+ end
65
+
66
+ # Hopefully no one has written their extensions in pre-0.9 style
67
+ # desc "Translate specs from pre-0.9 to 0.9 style"
68
+ # task :translate do
69
+ # translator = ::Spec::Translator.new
70
+ # dir = RAILS_ROOT + '/spec'
71
+ # translator.translate(dir, dir)
72
+ # end
73
+
74
+ # Setup specs for stats
75
+ task :statsetup do
76
+ require 'code_statistics'
77
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
78
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
79
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
80
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
81
+ ::CodeStatistics::TEST_TYPES << "Model specs"
82
+ ::CodeStatistics::TEST_TYPES << "View specs"
83
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
84
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
85
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86
+ end
87
+
88
+ namespace :db do
89
+ namespace :fixtures do
90
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91
+ task :load => :environment do
92
+ require 'active_record/fixtures'
93
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc 'Generate documentation for the flat_rate_shipping extension.'
103
+ Rake::RDocTask.new(:rdoc) do |rdoc|
104
+ rdoc.rdoc_dir = 'rdoc'
105
+ rdoc.title = 'FlatRateShippingExtension'
106
+ rdoc.options << '--line-numbers' << '--inline-source'
107
+ rdoc.rdoc_files.include('README')
108
+ rdoc.rdoc_files.include('lib/**/*.rb')
109
+ end
110
+
111
+ # For extensions that are in transition
112
+ desc 'Test the flat_rate_shipping extension.'
113
+ Rake::TestTask.new(:test) do |t|
114
+ t.libs << 'lib'
115
+ t.pattern = 'test/**/*_test.rb'
116
+ t.verbose = true
117
+ end
118
+
119
+ # Load any custom rakefiles for extension
120
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,17 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application'
3
+
4
+ class FlatRateShippingExtension < Spree::Extension
5
+ version "1.0"
6
+ description "Provides FlatRate shiping_calculator"
7
+
8
+ # define_routes do |map|
9
+ # map.namespace :admin do |admin|
10
+ # admin.resources :whatever
11
+ # end
12
+ # end
13
+
14
+ def activate
15
+ # admin.tabs.add "Flat Rate Shipping", "/admin/flat_rate_shipping", :after => "Layouts", :visibility => [:all]
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ class FlatRateShippingConfiguration < Configuration
2
+
3
+ preference :flat_rate_amount, :decimal, :default => 12.99
4
+
5
+ validates_presence_of :name
6
+ validates_uniqueness_of :name
7
+ end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module FlatRateShipping
3
+ class Calculator
4
+ def calculate_shipping(order)
5
+ return Spree::FlatRateShipping::Config[:flat_rate_amount]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Spree
2
+ module FlatRateShipping
3
+ # Singleton class to access the tax configuration object (TaxConfiguration.first by default) and it's preferences.
4
+ #
5
+ # Usage:
6
+ # Spree::FlatRateShipping::Config[:foo] # Returns the foo preference
7
+ # Spree::FlatRateShipping::Config[] # Returns a Hash with all the tax preferences
8
+ # Spree::FlatRateShipping::Config.instance # Returns the configuration object (TaxConfiguration.first)
9
+ # Spree::FlatRateShipping::Config.set(preferences_hash) # Set the tax preferences as especified in +preference_hash+
10
+ class Config
11
+ include Singleton
12
+ include PreferenceAccess
13
+
14
+ class << self
15
+ def instance
16
+ return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
17
+ FlatRateShippingConfiguration.find_or_create_by_name("Default tax configuration")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end