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
@@ -0,0 +1,32 @@
1
+ require 'rails_generator/base'
2
+
3
+ class ExtensionMigrationGenerator < Rails::Generator::NamedBase
4
+
5
+ attr_reader :extension_path, :extension_file_name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ @extension_file_name = "#{file_name}_extension"
10
+ @extension_path = "vendor/extensions/#{file_name}"
11
+ @migration_name = runtime_args[1]
12
+ end
13
+
14
+ # overload the super method which was causing problems for some unknown reason (too lazy to debug properly)
15
+ def attributes
16
+ []
17
+ end
18
+
19
+ #def banner
20
+ # "Usage: #{$0} extension_migration ExtensionName MigrationName"
21
+ #end
22
+
23
+ def manifest
24
+ record do |m|
25
+ m.migration_template 'migration.rb',
26
+ "#{extension_path}/db/migrate",
27
+ :assigns => {:migration_name => @migration_name},
28
+ :migration_file_name => @migration_name
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,7 @@
1
+ class <%= migration_name.titleize.gsub(" ", "") %> < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
data/lib/spree.rb CHANGED
@@ -8,8 +8,8 @@ unless defined? Spree::Version
8
8
  module Spree
9
9
  module Version
10
10
  Major = '0'
11
- Minor = '4'
12
- Tiny = '1'
11
+ Minor = '5'
12
+ Tiny = '0'
13
13
 
14
14
  class << self
15
15
  def to_s
@@ -37,13 +37,6 @@ module Spree
37
37
  end
38
38
  alias :activate :activate_extension
39
39
 
40
- def deactivate_extension
41
- return unless instance.active?
42
- instance.active = false
43
- instance.deactivate if instance.respond_to? :deactivate
44
- end
45
- alias :deactivate :deactivate_extension
46
-
47
40
  def define_routes(&block)
48
41
  route_definitions << block
49
42
  end
@@ -14,10 +14,6 @@ module Spree
14
14
  @config = rails_config
15
15
  end
16
16
 
17
- def before_clear(*args)
18
- ExtensionLoader.deactivate_extensions
19
- end
20
-
21
17
  def after_clear(*args)
22
18
  ExtensionLoader.load_extensions
23
19
  ExtensionLoader.activate_extensions
@@ -84,10 +80,6 @@ module Spree
84
80
  end.compact
85
81
  end
86
82
 
87
- def deactivate_extensions
88
- extensions.each &:deactivate
89
- end
90
-
91
83
  def activate_extensions
92
84
  # initializer.initialize_default_admin_tabs
93
85
  # Reset the view paths after
@@ -117,6 +117,53 @@ namespace :spec do
117
117
  end
118
118
  end
119
119
 
120
+ namespace :extensions do
121
+ desc "List the gems that the extensions depends on"
122
+ task :gems => [ 'gems:base' ] do
123
+ config = create_config
124
+
125
+ config.gems.each do |gem|
126
+ gem.add_load_paths
127
+ gem.load
128
+ code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " "
129
+ puts "[#{code}] #{gem.name} #{gem.requirement.to_s}"
130
+ end
131
+ puts
132
+ puts "I = Installed"
133
+ puts "F = Frozen"
134
+ end
135
+
136
+ namespace :gems do
137
+ task :base do
138
+ $rails_gem_installer = true
139
+ Rake::Task[:environment].invoke
140
+ end
141
+
142
+ def create_config
143
+ config = Rails::Configuration.new
144
+
145
+ Spree::Extension.descendants.each do |extension|
146
+ if extension.respond_to? :require_gems
147
+ extension.require_gems(config)
148
+ end
149
+ end
150
+
151
+ config
152
+ end
153
+
154
+ desc "Installs all required gems for the extensions."
155
+ task :install => :base do
156
+ require 'rubygems'
157
+ require 'rubygems/gem_runner'
158
+
159
+ config = create_config
160
+
161
+ config.gems.each { |gem| gem.install unless gem.loaded? }
162
+ end
163
+ end
164
+
165
+ end
166
+
120
167
  # Load any custom rakefiles from extensions
121
168
  [RAILS_ROOT, SPREE_ROOT].uniq.each do |root|
122
169
  Dir[root + '/vendor/extensions/*/lib/tasks/*.rake'].sort.each { |ext| load ext }
@@ -1,2 +1,36 @@
1
1
  // Place your application-specific JavaScript functions and classes here
2
2
  // This file is automatically included by javascript_include_tag :defaults
3
+
4
+ var shipping_costs = new Hash();
5
+
6
+ function calculate_order_total(radio){
7
+ $('order_total_cell').update(number_to_currency(order_total_without_shipping + shipping_costs.get(radio.value)));
8
+ }
9
+
10
+ function number_to_currency(number, options) {
11
+ try {
12
+ var options = options || {};
13
+ var precision = options["precision"] || 2;
14
+ var unit = options["unit"] || "$";
15
+ var separator = precision > 0 ? options["separator"] || "." : "";
16
+ var delimiter = options["delimiter"] || ",";
17
+
18
+ var parts = parseFloat(number).toFixed(precision).split('.');
19
+ return unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
20
+ } catch(e) {
21
+ return number
22
+ }
23
+ }
24
+
25
+ function number_with_delimiter(number, delimiter, separator) {
26
+ try {
27
+ var delimiter = delimiter || ",";
28
+ var separator = separator || ".";
29
+
30
+ var parts = number.toString().split('.');
31
+ parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);
32
+ return parts.join(separator);
33
+ } catch(e) {
34
+ return number
35
+ }
36
+ }
@@ -31,8 +31,8 @@ spree.YUI = {
31
31
 
32
32
  var target_url = target.data.object_url.split('/');
33
33
  var parent_id = target_url.last();
34
- target_url = target_url.without(parent_id);
35
-
34
+ target_url = target_url.slice(0, (target_url.length - 1))
35
+
36
36
  //add inplace creator
37
37
  var ipe = new Ajax.InPlaceEditor('new_taxon_node_' + rand_no, target_url.join('/'), {
38
38
  callback: function(form, value) { return 'taxon[name]=' + encodeURIComponent(value) + '&taxon[parent_id]=' + encodeURIComponent(parent_id)},
@@ -393,4 +393,14 @@ li.preview a {
393
393
  #variants li {
394
394
  list-style-type: none;
395
395
  }
396
- /** ================ end: product-related =================== */
396
+ /** ================ end: product-related =================== */
397
+
398
+ /** ================ begin: simple-radios =================== */
399
+ .simple-radios li {
400
+ list-style-type: none;
401
+ }
402
+ /** ================ end: simple-radios =================== */
403
+
404
+ .disabled {
405
+ color: #AFAFAF;
406
+ }
@@ -1,7 +1,15 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1
+ inventory_allow_backorders:
2
+ id: 1
3
+ attribute: allow_backorders
4
+ owner_id: 1
5
+ owner_type: Configuration
6
+ value: 0
7
+ created_at: <%= Time.now %>
2
8
 
3
- # one:
4
- # column: value
5
- #
6
- # two:
7
- # column: value
9
+ inventory_show_zero_stock_products:
10
+ id: 2
11
+ attribute: show_zero_stock_products
12
+ owner_id: 1
13
+ owner_type: Configuration
14
+ value: 0
15
+ created_at: <%= Time.now %>
@@ -0,0 +1,78 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module AddressSpecHelper
4
+ def valid_address_attributes
5
+ {
6
+ :firstname => "First",
7
+ :lastname => "Last",
8
+ :address1 => "Address1",
9
+ :city => "City",
10
+ :state_name => "A State",
11
+ :zipcode => "00000",
12
+ :country => Country.new,
13
+ :phone => "00000000"
14
+ }
15
+ end
16
+ end
17
+
18
+
19
+ describe Address do
20
+ include AddressSpecHelper
21
+
22
+ before(:each) do
23
+ @address = Address.new
24
+ end
25
+
26
+ it "should not be valid when empty" do
27
+ @address.should_not be_valid
28
+ end
29
+
30
+ ['firstname', 'lastname', 'address1', 'city', 'country', 'zipcode', 'phone'].each do |field|
31
+ it "should require #{field}" do
32
+ @address.should_not be_valid
33
+ @address.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
34
+ end
35
+ end
36
+
37
+ it "should require a state name when the associated country don't have states" do
38
+ @address.attributes = valid_address_attributes.with(:state_name => "")
39
+
40
+ @address.should_not be_valid
41
+ @address.errors.full_messages.should include("#{'state_name'.intern.l('state_name').humanize} #{:error_message_blank.l}")
42
+ end
43
+
44
+ it "should require a state when the associated country have states" do
45
+ @address.attributes = valid_address_attributes.with(
46
+ :country => Country.new(:states => [State.new(:name => "A State", :abbr => "ST")])
47
+ )
48
+
49
+ @address.should_not be_valid
50
+ @address.errors.full_messages.should include("#{'state'.intern.l('state').humanize} #{:error_message_blank.l}")
51
+ end
52
+
53
+ it "should be valid when having correct information" do
54
+ @address.attributes = valid_address_attributes
55
+ @address.should be_valid
56
+ end
57
+
58
+ it "should return full name when requested" do
59
+ @address.attributes = valid_address_attributes
60
+ @address.full_name.should == @address.firstname + " " + @address.lastname
61
+ end
62
+
63
+ it "should return state text as state_name attribute when the associated state is nil" do
64
+ @address.attributes = valid_address_attributes.except(:state)
65
+ @address.state_text.should == @address.state_name
66
+ end
67
+
68
+ it "should return state text as state.name attribute when the associated state is not nil but the abbreviation is empty" do
69
+ @address.attributes = valid_address_attributes.with(:state => State.new(:name => "A State", :abbr => ""))
70
+ @address.state_text.should == @address.state.name
71
+ end
72
+
73
+ it "should return state text as state.abbr attribute when the associated state is not nil and the abbreviation is not empty" do
74
+ @address.attributes = valid_address_attributes.with(:state => State.new(:name => "A State", :abbr => "ST"))
75
+ @address.state_text.should == @address.state.abbr
76
+ end
77
+
78
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Country do
4
+
5
+ before(:each) do
6
+ @country = Country.new
7
+ end
8
+
9
+ it "should not be valid when empty" do
10
+ pending "Can it really be valid when empty?"
11
+ @country.should_not be_valid
12
+ end
13
+
14
+ it "should be valid when having correct information" do
15
+ @country.iso_name = "A Country"
16
+
17
+ @country.should be_valid
18
+ end
19
+
20
+
21
+ ['iso_name'].each do |field|
22
+ it "should require #{field}" do
23
+ pending "Is this field mandatory?"
24
+ @country.should_not be_valid
25
+ @country.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module OptionTypeSpecHelper
4
+ def valid_option_type_attributes
5
+ {
6
+ :name => "an_option_type",
7
+ :presentation => "An Option Type"
8
+ }
9
+ end
10
+ end
11
+
12
+
13
+ describe OptionType do
14
+ include OptionTypeSpecHelper
15
+
16
+ before(:each) do
17
+ @option_type = OptionType.new
18
+ end
19
+
20
+ it "should not be valid when empty" do
21
+ @option_type.should_not be_valid
22
+ end
23
+
24
+ ['name', 'presentation'].each do |field|
25
+ it "should require #{field}" do
26
+ @option_type.should_not be_valid
27
+ @option_type.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
+ @option_type.attributes = valid_option_type_attributes
33
+ @option_type.should be_valid
34
+ end
35
+
36
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module OptionValueSpecHelper
4
+ def valid_option_value_attributes
5
+ {
6
+ :name => "an_option_value",
7
+ :presentation => "An Option Value",
8
+ :position => 1
9
+ }
10
+ end
11
+ end
12
+
13
+
14
+ describe OptionValue do
15
+ include OptionValueSpecHelper
16
+
17
+ before(:each) do
18
+ @option_value = OptionValue.new
19
+ end
20
+
21
+ it "should not be valid when empty" do
22
+ pending "Shouldn't it require a name and a presentation?"
23
+ @option_value.should_not be_valid
24
+ end
25
+
26
+ ['name', 'presentation'].each do |field|
27
+ it "should require #{field}" do
28
+ pending "Shouldn't it require a name and a presentation?"
29
+ @option_value.should_not be_valid
30
+ @option_value.errors.full_messages.should include("#{field.intern.l(field).humanize} #{:error_message_blank.l}")
31
+ end
32
+ end
33
+
34
+ it "should be valid when having correct information" do
35
+ @option_value.attributes = valid_option_value_attributes
36
+ @option_value.should be_valid
37
+ end
38
+
39
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module ProductOptionTypeSpecHelper
4
+ def valid_product_option_type_attributes
5
+ {
6
+ :position => 1
7
+ }
8
+ end
9
+ end
10
+
11
+
12
+ describe ProductOptionType do
13
+ include ProductOptionTypeSpecHelper
14
+
15
+ before(:each) do
16
+ @product_option_type = ProductOptionType.new
17
+ end
18
+
19
+ it "should not be valid when empty" do
20
+ pending "Shouldn't it require a position?"
21
+ @product_option_type.should_not be_valid
22
+ end
23
+
24
+ ['position'].each do |field|
25
+ it "should require #{field}" do
26
+ pending "Shouldn't it require a position?"
27
+ @product_option_type.should_not be_valid
28
+ @product_option_type.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
+ pending "Shouldn't it require a product and an option type too?"
34
+ @product_option_type.attributes = valid_product_option_type_attributes
35
+ @product_option_type.should be_valid
36
+ end
37
+
38
+ end