spree_sample 3.1.14 → 3.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,11 @@
1
- Spree::Gateway::Bogus.create!(
2
- {
3
- name: "Credit Card",
4
- description: "Bogus payment gateway.",
5
- active: true
6
- }
7
- )
1
+ Spree::Gateway::Bogus.where(
2
+ name: "Credit Card",
3
+ description: "Bogus payment gateway.",
4
+ active: true
5
+ ).first_or_create!
8
6
 
9
- Spree::PaymentMethod::Check.create!(
10
- {
11
- name: "Check",
12
- description: "Pay by check.",
13
- active: true
14
- }
15
- )
7
+ Spree::PaymentMethod::Check.where(
8
+ name: "Check",
9
+ description: "Pay by check.",
10
+ active: true
11
+ ).first_or_create!
@@ -1,5 +1,5 @@
1
1
  # create payments based on the totals since they can't be known in YAML (quantities are random)
2
- method = Spree::PaymentMethod.where(:name => 'Credit Card', :active => true).first
2
+ method = Spree::PaymentMethod.where(name: 'Credit Card', active: true).first
3
3
 
4
4
  # Hack the current method so we're able to return a gateway without a RAILS_ENV
5
5
  Spree::Gateway.class_eval do
@@ -12,11 +12,18 @@ end
12
12
  # reference it as such. Make it explicit here that this table has been renamed.
13
13
  Spree::CreditCard.table_name = 'spree_credit_cards'
14
14
 
15
- creditcard = Spree::CreditCard.create(:cc_type => 'visa', :month => 12, :year => 2.years.from_now.year, :last_digits => '1111',
16
- :name => 'Sean Schofield', :gateway_customer_profile_id => 'BGS-1234')
15
+ credit_card = Spree::CreditCard.where(cc_type: 'visa',
16
+ month: 12,
17
+ year: 2.years.from_now.year,
18
+ last_digits: '1111',
19
+ name: 'Sean Schofield',
20
+ gateway_customer_profile_id: 'BGS-1234').first_or_create!
17
21
 
18
- Spree::Order.all.each_with_index do |order, index|
22
+ Spree::Order.all.each_with_index do |order, _index|
19
23
  order.update_with_updater!
20
- payment = order.payments.create!(:amount => order.total, :source => creditcard.clone, :payment_method => method)
21
- payment.update_columns(:state => 'pending', :response_code => '12345')
24
+ payment = order.payments.where(amount: BigDecimal(order.total, 4),
25
+ source: credit_card.clone,
26
+ payment_method: method).first_or_create!
27
+
28
+ payment.update_columns(state: 'pending', response_code: '12345')
22
29
  end
@@ -1,7 +1,7 @@
1
1
  products =
2
- {
3
- "Ruby on Rails Baseball Jersey" =>
4
- {
2
+ {
3
+ "Ruby on Rails Baseball Jersey" =>
4
+ {
5
5
  "Manufacturer" => "Wilson",
6
6
  "Brand" => "Wannabe Sports",
7
7
  "Model" => "JK1002",
@@ -36,44 +36,44 @@ products =
36
36
  "Ruby on Rails Tote" =>
37
37
  {
38
38
  "Type" => "Tote",
39
- "Size" => %Q{15" x 18" x 6"},
39
+ "Size" => %{15" x 18" x 6"},
40
40
  "Material" => "Canvas"
41
41
  },
42
42
  "Ruby on Rails Bag" =>
43
43
  {
44
44
  "Type" => "Messenger",
45
- "Size" => %Q{14 1/2" x 12" x 5"},
45
+ "Size" => %{14 1/2" x 12" x 5"},
46
46
  "Material" => "600 Denier Polyester"
47
47
  },
48
- "Ruby on Rails Mug" =>
48
+ "Ruby on Rails Mug" =>
49
49
  {
50
50
  "Type" => "Mug",
51
- "Size" => %Q{4.5" tall, 3.25" dia.}
51
+ "Size" => %{4.5" tall, 3.25" dia.}
52
52
  },
53
53
  "Ruby on Rails Stein" =>
54
54
  {
55
55
  "Type" => "Stein",
56
- "Size" => %Q{6.75" tall, 3.75" dia. base, 3" dia. rim}
56
+ "Size" => %{6.75" tall, 3.75" dia. base, 3" dia. rim}
57
57
  },
58
58
  "Spree Stein" =>
59
59
  {
60
60
  "Type" => "Stein",
61
- "Size" => %Q{6.75" tall, 3.75" dia. base, 3" dia. rim}
61
+ "Size" => %{6.75" tall, 3.75" dia. base, 3" dia. rim}
62
62
  },
63
- "Spree Mug" =>
63
+ "Spree Mug" =>
64
64
  {
65
65
  "Type" => "Mug",
66
- "Size" => %Q{4.5" tall, 3.25" dia.}
66
+ "Size" => %{4.5" tall, 3.25" dia.}
67
67
  },
68
- "Spree Tote" =>
68
+ "Spree Tote" =>
69
69
  {
70
70
  "Type" => "Tote",
71
- "Size" => %Q{15" x 18" x 6"}
71
+ "Size" => %{15" x 18" x 6"}
72
72
  },
73
- "Spree Bag" =>
73
+ "Spree Bag" =>
74
74
  {
75
75
  "Type" => "Messenger",
76
- "Size" => %Q{14 1/2" x 12" x 5"}
76
+ "Size" => %{14 1/2" x 12" x 5"}
77
77
  },
78
78
  "Spree Baseball Jersey" =>
79
79
  {
@@ -2,136 +2,123 @@ Spree::Sample.load_sample("tax_categories")
2
2
  Spree::Sample.load_sample("shipping_categories")
3
3
 
4
4
  clothing = Spree::TaxCategory.find_by_name!("Clothing")
5
- shipping_category = Spree::ShippingCategory.find_by_name!("Default")
6
-
7
- default_attrs = {
8
- description: FFaker::Lorem.paragraph,
9
- available_on: Time.zone.now
10
- }
11
5
 
12
6
  products = [
13
7
  {
14
- :name => "Ruby on Rails Tote",
15
- :tax_category => clothing,
16
- :shipping_category => shipping_category,
17
- :price => 15.99,
18
- :eur_price => 14,
8
+ name: "Ruby on Rails Tote",
9
+ tax_category: clothing,
10
+ price: 15.99,
11
+ eur_price: 14,
19
12
  },
20
13
  {
21
- :name => "Ruby on Rails Bag",
22
- :tax_category => clothing,
23
- :shipping_category => shipping_category,
24
- :price => 22.99,
25
- :eur_price => 19,
14
+ name: "Ruby on Rails Bag",
15
+ tax_category: clothing,
16
+ price: 22.99,
17
+ eur_price: 19,
26
18
  },
27
19
  {
28
- :name => "Ruby on Rails Baseball Jersey",
29
- :tax_category => clothing,
30
- :shipping_category => shipping_category,
31
- :price => 19.99,
32
- :eur_price => 16
20
+ name: "Ruby on Rails Baseball Jersey",
21
+ tax_category: clothing,
22
+ price: 19.99,
23
+ eur_price: 16
33
24
  },
34
25
  {
35
- :name => "Ruby on Rails Jr. Spaghetti",
36
- :tax_category => clothing,
37
- :shipping_category => shipping_category,
38
- :price => 19.99,
39
- :eur_price => 16
26
+ name: "Ruby on Rails Jr. Spaghetti",
27
+ tax_category: clothing,
28
+ price: 19.99,
29
+ eur_price: 16
40
30
 
41
31
  },
42
32
  {
43
- :name => "Ruby on Rails Ringer T-Shirt",
44
- :shipping_category => shipping_category,
45
- :tax_category => clothing,
46
- :price => 19.99,
47
- :eur_price => 16
33
+ name: "Ruby on Rails Ringer T-Shirt",
34
+ tax_category: clothing,
35
+ price: 19.99,
36
+ eur_price: 16
48
37
  },
49
38
  {
50
- :name => "Ruby Baseball Jersey",
51
- :tax_category => clothing,
52
- :shipping_category => shipping_category,
53
- :price => 19.99,
54
- :eur_price => 16
39
+ name: "Ruby Baseball Jersey",
40
+ tax_category: clothing,
41
+ price: 19.99,
42
+ eur_price: 16
55
43
  },
56
44
  {
57
- :name => "Apache Baseball Jersey",
58
- :tax_category => clothing,
59
- :shipping_category => shipping_category,
60
- :price => 19.99,
61
- :eur_price => 16
45
+ name: "Apache Baseball Jersey",
46
+ tax_category: clothing,
47
+ price: 19.99,
48
+ eur_price: 16
62
49
  },
63
50
  {
64
- :name => "Spree Baseball Jersey",
65
- :tax_category => clothing,
66
- :shipping_category => shipping_category,
67
- :price => 19.99,
68
- :eur_price => 16
51
+ name: "Spree Baseball Jersey",
52
+ tax_category: clothing,
53
+ price: 19.99,
54
+ eur_price: 16
69
55
  },
70
56
  {
71
- :name => "Spree Jr. Spaghetti",
72
- :tax_category => clothing,
73
- :shipping_category => shipping_category,
74
- :price => 19.99,
75
- :eur_price => 16
57
+ name: "Spree Jr. Spaghetti",
58
+ tax_category: clothing,
59
+ price: 19.99,
60
+ eur_price: 16
76
61
  },
77
62
  {
78
- :name => "Spree Ringer T-Shirt",
79
- :tax_category => clothing,
80
- :shipping_category => shipping_category,
81
- :price => 19.99,
82
- :eur_price => 16
63
+ name: "Spree Ringer T-Shirt",
64
+ tax_category: clothing,
65
+ price: 19.99,
66
+ eur_price: 16
83
67
  },
84
68
  {
85
- :name => "Spree Tote",
86
- :tax_category => clothing,
87
- :shipping_category => shipping_category,
88
- :price => 15.99,
89
- :eur_price => 14,
69
+ name: "Spree Tote",
70
+ tax_category: clothing,
71
+ price: 15.99,
72
+ eur_price: 14,
90
73
  },
91
74
  {
92
- :name => "Spree Bag",
93
- :tax_category => clothing,
94
- :shipping_category => shipping_category,
95
- :price => 22.99,
96
- :eur_price => 19
75
+ name: "Spree Bag",
76
+ tax_category: clothing,
77
+ price: 22.99,
78
+ eur_price: 19
97
79
  },
98
80
  {
99
- :name => "Ruby on Rails Mug",
100
- :shipping_category => shipping_category,
101
- :price => 13.99,
102
- :eur_price => 12
81
+ name: "Ruby on Rails Mug",
82
+ price: 13.99,
83
+ eur_price: 12
103
84
  },
104
85
  {
105
- :name => "Ruby on Rails Stein",
106
- :shipping_category => shipping_category,
107
- :price => 16.99,
108
- :eur_price => 14
86
+ name: "Ruby on Rails Stein",
87
+ price: 16.99,
88
+ eur_price: 14
109
89
  },
110
90
  {
111
- :name => "Spree Stein",
112
- :shipping_category => shipping_category,
113
- :price => 16.99,
114
- :eur_price => 14,
91
+ name: "Spree Stein",
92
+ price: 16.99,
93
+ eur_price: 14,
115
94
  },
116
95
  {
117
- :name => "Spree Mug",
118
- :shipping_category => shipping_category,
119
- :price => 13.99,
120
- :eur_price => 12
96
+ name: "Spree Mug",
97
+ price: 13.99,
98
+ eur_price: 12
121
99
  }
122
100
  ]
123
101
 
102
+ default_shipping_category = Spree::ShippingCategory.find_by_name!("Default")
103
+
124
104
  products.each do |product_attrs|
125
- eur_price = product_attrs.delete(:eur_price)
126
105
  Spree::Config[:currency] = "USD"
106
+ eur_price = product_attrs.delete(:eur_price)
107
+
108
+ new_product = Spree::Product.where(name: product_attrs[:name],
109
+ tax_category: product_attrs[:tax_category]).first_or_create! do |product|
110
+ product.price = product_attrs[:price]
111
+ product.description = FFaker::Lorem.paragraph
112
+ product.available_on = Time.zone.now
113
+ product.shipping_category = default_shipping_category
114
+ end
127
115
 
128
- default_shipping_category = Spree::ShippingCategory.find_by_name!("Default")
129
- product = Spree::Product.create!(default_attrs.merge(product_attrs))
130
- Spree::Config[:currency] = "EUR"
131
- product.reload
132
- product.price = eur_price
133
- product.shipping_category = default_shipping_category
134
- product.save!
116
+ if new_product
117
+ Spree::Config[:currency] = "EUR"
118
+ new_product.reload
119
+ new_product.price = eur_price
120
+ new_product.save
121
+ end
135
122
  end
136
123
 
137
124
  Spree::Config[:currency] = "USD"
@@ -1,21 +1,22 @@
1
1
  prototypes = [
2
2
  {
3
- :name => "Shirt",
4
- :properties => ["Manufacturer", "Brand", "Model", "Shirt Type", "Sleeve Type", "Material", "Fit", "Gender"]
3
+ name: "Shirt",
4
+ properties: ["Manufacturer", "Brand", "Model", "Shirt Type", "Sleeve Type", "Material", "Fit", "Gender"]
5
5
  },
6
6
  {
7
- :name => "Bag",
8
- :properties => ["Type", "Size", "Material"]
7
+ name: "Bag",
8
+ properties: ["Type", "Size", "Material"]
9
9
  },
10
10
  {
11
- :name => "Mugs",
12
- :properties => ["Size", "Type"]
11
+ name: "Mugs",
12
+ properties: ["Size", "Type"]
13
13
  }
14
14
  ]
15
15
 
16
16
  prototypes.each do |prototype_attrs|
17
- prototype = Spree::Prototype.create!(:name => prototype_attrs[:name])
18
- prototype_attrs[:properties].each do |property|
19
- prototype.properties << Spree::Property.where(name: property).first
17
+ prototype = Spree::Prototype.where(name: prototype_attrs[:name]).first_or_create!
18
+ prototype_attrs[:properties].each do |property_name|
19
+ property = Spree::Property.where(name: property_name).first
20
+ prototype.properties << property unless prototype.properties.include?(property)
20
21
  end
21
22
  end
@@ -1 +1 @@
1
- Spree::ShippingCategory.find_or_create_by!(:name => "Default")
1
+ Spree::ShippingCategory.find_or_create_by!(name: 'Default')
@@ -1,5 +1,5 @@
1
1
  begin
2
- north_america = Spree::Zone.find_by_name!("North America")
2
+ north_america = Spree::Zone.find_by_name!("North America")
3
3
  rescue ActiveRecord::RecordNotFound
4
4
  puts "Couldn't find 'North America' zone. Did you run `rake db:seed` first?"
5
5
  puts "That task will set up the countries, states and zones required for Spree."
@@ -9,38 +9,41 @@ end
9
9
  europe_vat = Spree::Zone.find_by_name!("EU_VAT")
10
10
  shipping_category = Spree::ShippingCategory.find_or_create_by!(name: 'Default')
11
11
 
12
- Spree::ShippingMethod.create!([
12
+ shipping_methods = [
13
13
  {
14
- :name => "UPS Ground (USD)",
15
- :zones => [north_america],
16
- :calculator => Spree::Calculator::Shipping::FlatRate.create!,
17
- :shipping_categories => [shipping_category]
14
+ name: "UPS Ground (USD)",
15
+ zones: [north_america],
16
+ shipping_categories: [shipping_category]
18
17
  },
19
18
  {
20
- :name => "UPS Two Day (USD)",
21
- :zones => [north_america],
22
- :calculator => Spree::Calculator::Shipping::FlatRate.create!,
23
- :shipping_categories => [shipping_category]
19
+ name: "UPS Two Day (USD)",
20
+ zones: [north_america],
21
+ shipping_categories: [shipping_category]
24
22
  },
25
23
  {
26
- :name => "UPS One Day (USD)",
27
- :zones => [north_america],
28
- :calculator => Spree::Calculator::Shipping::FlatRate.create!,
29
- :shipping_categories => [shipping_category]
24
+ name: "UPS One Day (USD)",
25
+ zones: [north_america],
26
+ shipping_categories: [shipping_category]
30
27
  },
31
28
  {
32
- :name => "UPS Ground (EU)",
33
- :zones => [europe_vat],
34
- :calculator => Spree::Calculator::Shipping::FlatRate.create!,
35
- :shipping_categories => [shipping_category]
29
+ name: "UPS Ground (EU)",
30
+ zones: [europe_vat],
31
+ shipping_categories: [shipping_category]
36
32
  },
37
33
  {
38
- :name => "UPS Ground (EUR)",
39
- :zones => [europe_vat],
40
- :calculator => Spree::Calculator::Shipping::FlatRate.create!,
41
- :shipping_categories => [shipping_category]
34
+ name: "UPS Ground (EUR)",
35
+ zones: [europe_vat],
36
+ shipping_categories: [shipping_category]
42
37
  }
43
- ])
38
+ ]
39
+
40
+ shipping_methods.each do |attributes|
41
+ Spree::ShippingMethod.where(name: attributes[:name]).first_or_create! do |shipping_method|
42
+ shipping_method.calculator = Spree::Calculator::Shipping::FlatRate.create!
43
+ shipping_method.zones = attributes[:zones]
44
+ shipping_method.shipping_categories = attributes[:shipping_categories]
45
+ end
46
+ end
44
47
 
45
48
  {
46
49
  "UPS Ground (USD)" => [5, "USD"],
@@ -57,4 +60,3 @@ Spree::ShippingMethod.create!([
57
60
  shipping_method.calculator.save!
58
61
  shipping_method.save!
59
62
  end
60
-