bodega 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +3 -0
- data/Gemfile +10 -6
- data/Gemfile.lock +50 -19
- data/VERSION +1 -1
- data/app/controllers/bodega/orders_controller.rb +21 -30
- data/app/helpers/bodega/application_helper.rb +1 -0
- data/app/helpers/bodega/cart_helper.rb +9 -25
- data/app/models/bodega/order.rb +113 -11
- data/app/models/bodega/order_product.rb +20 -26
- data/app/models/bodega/product.rb +9 -12
- data/app/views/bodega/orders/_cart.html.erb +26 -0
- data/app/views/bodega/orders/_cart_row.html.erb +24 -0
- data/app/views/bodega/orders/_shipping_row.html.erb +13 -0
- data/app/views/bodega/orders/edit.html.erb +1 -0
- data/app/views/bodega/orders/new.html.erb +2 -38
- data/bodega.gemspec +30 -12
- data/config/locales/en.yml +13 -0
- data/config/routes.rb +9 -9
- data/db/migrate/20121111170337_create_bodega_orders.rb +12 -0
- data/lib/bodega/engine.rb +0 -1
- data/lib/bodega/optional.rb +12 -0
- data/lib/bodega/payment_method/base.rb +5 -13
- data/lib/bodega/payment_method/paypal.rb +12 -4
- data/lib/bodega/payment_method.rb +0 -4
- data/lib/bodega/shipping_method/base.rb +71 -0
- data/lib/bodega/shipping_method/ups.rb +18 -0
- data/lib/bodega/shipping_method.rb +5 -0
- data/lib/bodega.rb +19 -1
- data/spec/lib/bodega/payment_method/base_spec.rb +12 -0
- data/spec/lib/bodega/shipping_method/base_spec.rb +12 -0
- data/spec/lib/bodega_spec.rb +18 -0
- data/spec/models/order_product_spec.rb +72 -0
- data/spec/models/order_spec.rb +93 -0
- data/spec/models/product_spec.rb +78 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/active_record.rb +43 -0
- data/spec/support/rails.rb +7 -0
- data/spec/support/vcr.rb +0 -0
- metadata +36 -18
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bodega/product'
|
3
|
+
|
4
|
+
describe Bodega::Product do
|
5
|
+
let(:product) { TestProduct.create!(price: 25) }
|
6
|
+
before do
|
7
|
+
TestProduct.send :include, Bodega::Product
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#in_stock?" do
|
11
|
+
it "returns true if the product is not stock-kept" do
|
12
|
+
product.should be_in_stock
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns true if the number_in_stock is greater than zero" do
|
16
|
+
product.keep_stock = true
|
17
|
+
product.number_in_stock = 1
|
18
|
+
product.save!
|
19
|
+
product.should be_in_stock
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false if the number_in_stock is less than zero" do
|
23
|
+
product.keep_stock = true
|
24
|
+
product.number_in_stock = 0
|
25
|
+
product.save!
|
26
|
+
product.should_not be_in_stock
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#max_quantity" do
|
31
|
+
it "returns the Bodega configuration value if the product is not stock-kept" do
|
32
|
+
Bodega.stub(:config) { OpenStruct.new(max_quantity: 10) }
|
33
|
+
product.max_quantity.should == Bodega.config.max_quantity
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".for_sale" do
|
38
|
+
it "returns products who are for sale today or don't have a start date" do
|
39
|
+
product_1 = TestProduct.create!(for_sale_at: Date.today, price: 25.00)
|
40
|
+
product_2 = TestProduct.create!(price: 30)
|
41
|
+
non_product_1 = TestProduct.create!(for_sale_at: 1.day.from_now, price: 100)
|
42
|
+
TestProduct.for_sale.should == [product_1, product_2]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns products whose not_for_sale_at are past" do
|
46
|
+
product_1 = TestProduct.create!(for_sale_at: Date.today, price: 25.00)
|
47
|
+
product_2 = TestProduct.create!(price: 30)
|
48
|
+
non_product_1 = TestProduct.create!(not_for_sale_at: 1.day.ago, price: 100)
|
49
|
+
TestProduct.for_sale.should == [product_1, product_2]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns products who don't have for_sale_at anything" do
|
53
|
+
product_1 = TestProduct.create!(price: 25.00)
|
54
|
+
product_2 = TestProduct.create!(price: 30)
|
55
|
+
product_3 = TestProduct.create!(price: 100)
|
56
|
+
TestProduct.for_sale.should == [product_1, product_2, product_3]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".popular" do
|
61
|
+
it "returns products in order of sales from high to low" do
|
62
|
+
require 'bodega/order_product'
|
63
|
+
|
64
|
+
product_1 = TestProduct.create!(price: 25.00)
|
65
|
+
3.times { Bodega::OrderProduct.create!(product: product_1, quantity: 5) }
|
66
|
+
product_2 = TestProduct.create!(price: 30)
|
67
|
+
5.times { Bodega::OrderProduct.create!(product: product_2, quantity: 5) }
|
68
|
+
product_3 = TestProduct.create!(price: 100)
|
69
|
+
4.times { Bodega::OrderProduct.create!(product: product_3, quantity: 5) }
|
70
|
+
|
71
|
+
TestProduct.popular.should == [product_2, product_3, product_1]
|
72
|
+
|
73
|
+
Bodega::OrderProduct.create!(product: product_1, quantity: 50)
|
74
|
+
|
75
|
+
TestProduct.popular.should == [product_1, product_2, product_3]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
require 'active_record'
|
8
|
+
require 'database_cleaner'
|
9
|
+
require 'logger'
|
10
|
+
require 'money-rails'
|
11
|
+
require 'vcr'
|
12
|
+
|
13
|
+
require 'bodega'
|
14
|
+
|
15
|
+
Dir[File.expand_path(File.join('support', '**', '*.rb'), File.dirname(__FILE__))].each do |file|
|
16
|
+
require file
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = "random"
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'bodega/product'
|
2
|
+
|
3
|
+
ActiveRecord::Base.logger = Logger.new(File.open('log/test.log', 'w+'))
|
4
|
+
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:', :pool => 5, :timeout => 5000})
|
5
|
+
|
6
|
+
I18n.load_path = %w(config/locales/en.yml)
|
7
|
+
|
8
|
+
MoneyRails::Hooks.init
|
9
|
+
|
10
|
+
class TestProduct < ActiveRecord::Base
|
11
|
+
include Bodega::Product
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.around do |example|
|
16
|
+
DatabaseCleaner.strategy = :truncation
|
17
|
+
DatabaseCleaner.start
|
18
|
+
example.run
|
19
|
+
DatabaseCleaner.clean
|
20
|
+
end
|
21
|
+
|
22
|
+
config.before :suite do
|
23
|
+
migrations_path = File.expand_path(File.join("..", "..", "db", "migrate"), File.dirname(__FILE__))
|
24
|
+
migrations = Dir[File.join(migrations_path, '*.rb')]
|
25
|
+
migrations.each do |migration_file|
|
26
|
+
require migration_file
|
27
|
+
migration_name = File.basename(migration_file, '.rb')
|
28
|
+
migration_name[/^\d+_/] = ''
|
29
|
+
migration_name = migration_name.camelize
|
30
|
+
puts migration_name.constantize.migrate(:up)
|
31
|
+
end
|
32
|
+
ActiveRecord::Schema.define do
|
33
|
+
create_table :test_products, :force => true do |t|
|
34
|
+
t.integer :price_cents
|
35
|
+
t.boolean :for_sale, default: true
|
36
|
+
t.boolean :keep_stock, default: false
|
37
|
+
t.integer :number_in_stock
|
38
|
+
t.datetime :for_sale_at
|
39
|
+
t.datetime :not_for_sale_at
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/support/vcr.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bodega
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 3.2.11
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,15 +26,15 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 3.2.11
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: configurator2
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.1.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,9 +42,9 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.1.3
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: i18n
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,30 +60,30 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: maintain
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- - '
|
67
|
+
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
type: :
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- - '
|
75
|
+
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: money-rails
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
|
-
type: :
|
86
|
+
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
@@ -115,6 +115,10 @@ files:
|
|
115
115
|
- app/models/bodega/order.rb
|
116
116
|
- app/models/bodega/order_product.rb
|
117
117
|
- app/models/bodega/product.rb
|
118
|
+
- app/views/bodega/orders/_cart.html.erb
|
119
|
+
- app/views/bodega/orders/_cart_row.html.erb
|
120
|
+
- app/views/bodega/orders/_shipping_row.html.erb
|
121
|
+
- app/views/bodega/orders/edit.html.erb
|
118
122
|
- app/views/bodega/orders/new.html.erb
|
119
123
|
- app/views/bodega/orders/show.html.erb
|
120
124
|
- bodega.gemspec
|
@@ -124,9 +128,13 @@ files:
|
|
124
128
|
- db/migrate/20121111170420_create_bodega_order_products.rb
|
125
129
|
- lib/bodega.rb
|
126
130
|
- lib/bodega/engine.rb
|
131
|
+
- lib/bodega/optional.rb
|
127
132
|
- lib/bodega/payment_method.rb
|
128
133
|
- lib/bodega/payment_method/base.rb
|
129
134
|
- lib/bodega/payment_method/paypal.rb
|
135
|
+
- lib/bodega/shipping_method.rb
|
136
|
+
- lib/bodega/shipping_method/base.rb
|
137
|
+
- lib/bodega/shipping_method/ups.rb
|
130
138
|
- lib/bodega/version.rb
|
131
139
|
- lib/generators/bodega/install/install_generator.rb
|
132
140
|
- lib/generators/bodega/product/USAGE
|
@@ -138,6 +146,16 @@ files:
|
|
138
146
|
- lib/generators/bodega/productize/templates/migration.rb
|
139
147
|
- lib/tasks/bodega_tasks.rake
|
140
148
|
- script/rails
|
149
|
+
- spec/lib/bodega/payment_method/base_spec.rb
|
150
|
+
- spec/lib/bodega/shipping_method/base_spec.rb
|
151
|
+
- spec/lib/bodega_spec.rb
|
152
|
+
- spec/models/order_product_spec.rb
|
153
|
+
- spec/models/order_spec.rb
|
154
|
+
- spec/models/product_spec.rb
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
- spec/support/active_record.rb
|
157
|
+
- spec/support/rails.rb
|
158
|
+
- spec/support/vcr.rb
|
141
159
|
homepage: http://github.com/flipsasser/bodega
|
142
160
|
licenses:
|
143
161
|
- MIT
|
@@ -153,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
171
|
version: '0'
|
154
172
|
segments:
|
155
173
|
- 0
|
156
|
-
hash:
|
174
|
+
hash: 2351638233694158038
|
157
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
176
|
none: false
|
159
177
|
requirements:
|