bodega 0.4.0 → 0.4.1

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/Rakefile CHANGED
@@ -24,6 +24,7 @@ Jeweler::Tasks.new do |gem|
24
24
  gem.email = "flip@x451.com"
25
25
  gem.authors = ["Flip Sasser"]
26
26
  # dependencies defined in Gemfile
27
+ gem.files.exclude "spec/**/*", ".rvmrc", ".rspec"
27
28
  end
28
29
  Jeweler::RubygemsDotOrgTasks.new
29
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -21,7 +21,7 @@ class Bodega::OrdersController < ApplicationController
21
21
 
22
22
  def create
23
23
  if current_order.update_attributes(params[:order])
24
- if params[:checkout]
24
+ if !current_order.new_shipping_rates? && params[:checkout]
25
25
  redirect_to current_order.payment_method.checkout_url(complete_order_url, new_order_url)
26
26
  else
27
27
  redirect_to new_order_path
@@ -44,6 +44,10 @@ module Bodega
44
44
  end
45
45
  end
46
46
 
47
+ def new_shipping_rates?
48
+ @new_shipping_rates
49
+ end
50
+
47
51
  def payment_method
48
52
  return nil unless Bodega.config.payment_method
49
53
  @payment_method ||= "Bodega::PaymentMethod::#{Bodega.config.payment_method.to_s.camelize}".constantize.new(self)
@@ -54,7 +58,7 @@ module Bodega
54
58
  end
55
59
 
56
60
  def ready?
57
- shipping_method.present? || shipping_rates.any?
61
+ shipping_method.nil? || shipping_rates.present?
58
62
  end
59
63
 
60
64
  def remove_product(item)
@@ -136,6 +140,7 @@ module Bodega
136
140
 
137
141
  def set_shipping_rates
138
142
  self.shipping_rates = postal_code.present? ? shipping_method.rates : nil
143
+ @new_shipping_rates = true
139
144
  end
140
145
 
141
146
  def set_total
data/bodega.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bodega"
8
- s.version = "0.3.1"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Flip Sasser"]
@@ -16,8 +16,6 @@ Gem::Specification.new do |s|
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
- ".rspec",
20
- ".rvmrc",
21
19
  "Gemfile",
22
20
  "Gemfile.lock",
23
21
  "MIT-LICENSE",
@@ -62,18 +60,7 @@ Gem::Specification.new do |s|
62
60
  "lib/generators/bodega/productize/USAGE",
63
61
  "lib/generators/bodega/productize/productize_generator.rb",
64
62
  "lib/generators/bodega/productize/templates/migration.rb",
65
- "lib/tasks/bodega_tasks.rake",
66
- "script/rails",
67
- "spec/lib/bodega/payment_method/base_spec.rb",
68
- "spec/lib/bodega/shipping_method/base_spec.rb",
69
- "spec/lib/bodega_spec.rb",
70
- "spec/models/order_product_spec.rb",
71
- "spec/models/order_spec.rb",
72
- "spec/models/product_spec.rb",
73
- "spec/spec_helper.rb",
74
- "spec/support/active_record.rb",
75
- "spec/support/rails.rb",
76
- "spec/support/vcr.rb"
63
+ "lib/tasks/bodega_tasks.rake"
77
64
  ]
78
65
  s.homepage = "http://github.com/flipsasser/bodega"
79
66
  s.licenses = ["MIT"]
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.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -98,8 +98,6 @@ extensions: []
98
98
  extra_rdoc_files:
99
99
  - README.md
100
100
  files:
101
- - .rspec
102
- - .rvmrc
103
101
  - Gemfile
104
102
  - Gemfile.lock
105
103
  - MIT-LICENSE
@@ -145,17 +143,6 @@ files:
145
143
  - lib/generators/bodega/productize/productize_generator.rb
146
144
  - lib/generators/bodega/productize/templates/migration.rb
147
145
  - lib/tasks/bodega_tasks.rake
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
159
146
  homepage: http://github.com/flipsasser/bodega
160
147
  licenses:
161
148
  - MIT
@@ -171,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
158
  version: '0'
172
159
  segments:
173
160
  - 0
174
- hash: 2351638233694158038
161
+ hash: -3124905005200788522
175
162
  required_rubygems_version: !ruby/object:Gem::Requirement
176
163
  none: false
177
164
  requirements:
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- -I app/controllers
3
- -I app/helpers
4
- -I app/models
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@bodega --create
data/script/rails DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
- ENGINE_PATH = File.expand_path('../../lib/bodega/engine', __FILE__)
6
-
7
- require 'rails/all'
8
- require 'rails/engine/commands'
@@ -1,12 +0,0 @@
1
- require 'bodega'
2
- require 'bodega/payment_method/base'
3
- require 'active_support/core_ext/string/inflections'
4
-
5
- describe Bodega::PaymentMethod::Base do
6
- describe ".options" do
7
- it "defines options on the Bodega configuration instance" do
8
- described_class.options(:a, :b, :z)
9
- Bodega.config.base.should_not be_nil
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- require 'bodega'
2
- require 'bodega/shipping_method/base'
3
- require 'active_support/core_ext/string/inflections'
4
-
5
- describe Bodega::PaymentMethod::Base do
6
- describe ".options" do
7
- it "defines options on the Bodega configuration instance" do
8
- described_class.options(:a, :b, :z)
9
- Bodega.config.base.should_not be_nil
10
- end
11
- end
12
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bodega do
4
- describe ".config" do
5
- describe "#payment_method" do
6
- it "auto-detects Paypal" do
7
- class Paypal; end
8
- Bodega.config.payment_method.should == :paypal
9
- end
10
- end
11
-
12
- describe "test_mode" do
13
- it "auto-detects test mode" do
14
- Bodega.config.test_mode.should be_true
15
- end
16
- end
17
- end
18
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'bodega/order_product'
3
-
4
- describe Bodega::OrderProduct do
5
- let(:product) { TestProduct.create!(product_attrs) }
6
- let(:product_attrs) { {price: 49.95} }
7
- let(:order_product) { described_class.new(product: product, quantity: 1) }
8
-
9
- describe "#identifier" do
10
- it "returns a friendly identifier" do
11
- order_product.identifier.should == "TestProduct.1"
12
- end
13
- end
14
-
15
- describe "#name" do
16
- it "defaults to a human-readable name" do
17
- order_product.name.should == "Test Product #1"
18
- end
19
-
20
- it "delegates to the product" do
21
- def product.name
22
- "Ohai"
23
- end
24
- order_product.name.should == "Ohai"
25
- end
26
- end
27
-
28
- describe "#quantity_and_name" do
29
- it "returns the quantity and the name" do
30
- order_product.quantity_and_name.should == "1 x Test Product #1"
31
- end
32
- end
33
-
34
- describe "#subtotal" do
35
- it "returns the subtotal for the product quantity" do
36
- product.stub(:price) { 25.0 }
37
- order_product.quantity = 2
38
- order_product.subtotal.should == 50.0
39
- end
40
- end
41
-
42
- describe "for stock-kept products" do
43
- let(:product_attrs) { {price: 49.95, keep_stock: true, number_in_stock: 1} }
44
-
45
- it "can't be saved if the product is out-of-stock" do
46
- product.stub(:in_stock?) { false }
47
- product.save!
48
- order_product.save
49
- order_product.errors[:quantity].first.should == "Sorry, this product is sold out."
50
- end
51
-
52
- it "notifies me if my quantity is higher than the number left" do
53
- order_product.quantity = 2
54
- order_product.save
55
- order_product.errors[:quantity].first.should == "There is only one in stock!"
56
- end
57
-
58
- it "can't be saved if the quantity is too high" do
59
- product.stub(:number_in_stock) { 2 }
60
- order_product.quantity = 3
61
- order_product.save
62
- order_product.errors[:quantity].first.should == "There are only 2 in stock!"
63
- end
64
-
65
- it "reduces Product#number_in_stock when #update_stock is called" do
66
- order_product.stub(:order) { OpenStruct.new }
67
- order_product.save!
68
- order_product.update_stock
69
- product.reload.number_in_stock.should == 0
70
- end
71
- end
72
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
- require 'bodega/order'
3
- require 'bodega/order_product'
4
- require 'bodega/product'
5
-
6
- describe Bodega::Order do
7
- before do
8
- TestProduct.send :include, Bodega::Product
9
- end
10
-
11
- let!(:product_1) { TestProduct.create!(price: 30) }
12
- let!(:product_2) { TestProduct.create!(price: 25) }
13
- let(:order) { Bodega::Order.new }
14
-
15
- describe "#payment_method" do
16
- require 'bodega'
17
- require 'bodega/payment_method'
18
- class Paypal; end
19
-
20
- it "returns an instance of Bodega::PaymentMethod::Base" do
21
- order.payment_method.should be_instance_of(Bodega::PaymentMethod::Paypal)
22
- end
23
-
24
- it "returns an instance of Bodega::PaymentMethod::Base with a reference to the order" do
25
- order.payment_method.order.should == order
26
- end
27
- end
28
-
29
- describe "#shipping_method" do
30
- require 'bodega'
31
- require 'bodega/shipping_method'
32
-
33
- before do
34
- Bodega.config { shipping_method :ups }
35
- module ActiveMerchant; module Shipping; class UPS; end; end; end
36
- end
37
-
38
- it "returns an instance of Bodega::ShippingMethod::Base" do
39
- order.shipping_method.should be_instance_of(Bodega::ShippingMethod::UPS)
40
- end
41
- end
42
-
43
- describe "#subtotal" do
44
- let(:cart) do
45
- {
46
- "TestProduct.1" => {
47
- product_type: "TestProduct",
48
- product_id: "1",
49
- quantity: "1"
50
- },
51
- "TestProduct.2" => {
52
- product_type: "TestProduct",
53
- product_id: "2",
54
- quantity: "2"
55
- }
56
- }
57
- end
58
-
59
- it "adds up the #order_products subtotals" do
60
- cart.each do |identifier, item|
61
- order.update_product(item)
62
- end
63
- order.save!
64
- order.subtotal.should == 80
65
- end
66
- end
67
-
68
- describe "cart management" do
69
- before { order.save! }
70
-
71
- it "defaults to quantity 1 when none given" do
72
- order.update_product(product_type: "TestProduct", product_id: 1)
73
- order.send(:order_product, "TestProduct.1").quantity.should == 1
74
- end
75
-
76
- it "accepts new quantities" do
77
- order.update_product(product_type: "TestProduct", product_id: 1, quantity: 10)
78
- order.send(:order_product, "TestProduct.1").quantity.should == 10
79
- end
80
-
81
- it "updates old quantities when no new quantity is given" do
82
- order.update_product(product_type: "TestProduct", product_id: 1, quantity: 10)
83
- order.update_product(product_type: "TestProduct", product_id: 1)
84
- order.send(:order_product, "TestProduct.1").quantity.should == 11
85
- end
86
-
87
- it "removes products when told to" do
88
- order.update_product(product_type: "TestProduct", product_id: 1, quantity: 10)
89
- order.update_product(product_type: "TestProduct", product_id: 1, quantity: 30, remove: "1")
90
- order.send(:order_product, "TestProduct.1").should be_nil
91
- end
92
- end
93
- end
@@ -1,78 +0,0 @@
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 DELETED
@@ -1,25 +0,0 @@
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
@@ -1,43 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- module Rails
2
- extend self
3
-
4
- def env
5
- OpenStruct.new(:development? => false, :test? => true)
6
- end
7
- end
data/spec/support/vcr.rb DELETED
File without changes