mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Convert factories from machinist to factory girl
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -50,7 +50,8 @@ group :test, :development do
|
||||
gem 'turn', '~> 0.8.3', :require => false
|
||||
gem 'rspec-rails'
|
||||
gem 'shoulda-matchers'
|
||||
gem 'machinist'
|
||||
gem 'factory_girl_rails'
|
||||
gem 'faker'
|
||||
gem 'capybara'
|
||||
gem 'database_cleaner', '0.7.1', :require => false
|
||||
gem 'spork', '~> 1.0rc'
|
||||
|
||||
11
Gemfile.lock
11
Gemfile.lock
@@ -115,6 +115,13 @@ GEM
|
||||
erubis (2.7.0)
|
||||
execjs (1.4.0)
|
||||
multi_json (~> 1.0)
|
||||
factory_girl (3.3.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (3.3.0)
|
||||
factory_girl (~> 3.3.0)
|
||||
railties (>= 3.0.0)
|
||||
faker (1.0.1)
|
||||
i18n (~> 0.4)
|
||||
ffaker (1.12.1)
|
||||
ffi (1.0.11)
|
||||
gyoku (0.4.5)
|
||||
@@ -141,7 +148,6 @@ GEM
|
||||
libv8 (3.3.10.4)
|
||||
libwebsocket (0.1.3)
|
||||
addressable
|
||||
machinist (2.0)
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
@@ -328,9 +334,10 @@ DEPENDENCIES
|
||||
capybara
|
||||
coffee-rails (~> 3.2.1)
|
||||
database_cleaner (= 0.7.1)
|
||||
factory_girl_rails
|
||||
faker
|
||||
haml
|
||||
jquery-rails
|
||||
machinist
|
||||
pg
|
||||
pry
|
||||
rails (= 3.2.3)
|
||||
|
||||
@@ -9,11 +9,11 @@ describe Spree::Product do
|
||||
|
||||
describe "validations" do
|
||||
it "is valid when created from factory" do
|
||||
Spree::Product.make.should be_valid
|
||||
build(:product).should be_valid
|
||||
end
|
||||
|
||||
it "requires at least one distributor" do
|
||||
product = Spree::Product.make
|
||||
product = build(:product)
|
||||
product.distributors.clear
|
||||
product.should_not be_valid
|
||||
end
|
||||
|
||||
@@ -8,8 +8,8 @@ feature %q{
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@supplier = Spree::Supplier.make!(:name => 'New supplier')
|
||||
@distributors = (1..3).map { |i| Spree::Distributor.make!(:name => "Distributor #{i}") }
|
||||
@supplier = create(:supplier, :name => 'New supplier')
|
||||
@distributors = (1..3).map { create(:distributor) }
|
||||
end
|
||||
|
||||
context "creating a product" do
|
||||
|
||||
@@ -9,17 +9,17 @@ feature %q{
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@distributor1 = Spree::Distributor.make!(:name => 'Eaterprises')
|
||||
@distributor2 = Spree::Distributor.make!(:name => 'Edible garden',
|
||||
:pickup_address => '12 Bungee Rd',
|
||||
:city => 'Carion',
|
||||
:pickup_times => 'Tuesday, 4 PM')
|
||||
@product = Spree::Product.make!(:name => 'Fuji apples')
|
||||
@distributor1 = create(:distributor, :name => 'Eaterprises')
|
||||
@distributor2 = create(:distributor, :name => 'Edible garden',
|
||||
:pickup_address => '12 Bungee Rd',
|
||||
:city => 'Carion',
|
||||
:pickup_times => 'Tuesday, 4 PM')
|
||||
@product = create(:product, :name => 'Fuji apples')
|
||||
|
||||
@zone = Spree::Zone.make!
|
||||
Spree::ZoneMember.create(zone: @zone, zoneable: Spree::Country.find_by_name('Australia'))
|
||||
Spree::ShippingMethod.make!(zone: @zone)
|
||||
Spree::PaymentMethod.make!
|
||||
@zone = create(:zone)
|
||||
create(:zone_member, zone: @zone, zoneable: Spree::Country.find_by_name('Australia'))
|
||||
create(:shipping_method, zone: @zone)
|
||||
create(:payment_method)
|
||||
end
|
||||
|
||||
context "Given I am buying a product", :js => true do
|
||||
|
||||
@@ -10,7 +10,7 @@ feature %q{
|
||||
|
||||
background do
|
||||
# Given some distributors
|
||||
3.times { Spree::Distributor.make! }
|
||||
3.times { create(:distributor) }
|
||||
end
|
||||
|
||||
scenario "viewing list of distributors" do
|
||||
|
||||
@@ -60,6 +60,7 @@ Spork.prefork do
|
||||
end
|
||||
|
||||
config.include Spree::UrlHelpers
|
||||
config.include FactoryGirl::Syntax::Methods
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
require 'machinist/active_record'
|
||||
|
||||
# Add your blueprints here.
|
||||
#
|
||||
Spree::Supplier.blueprint do
|
||||
name { "Supplier" }
|
||||
description { 'supplier ' }
|
||||
email { 'email@somewhere.com' }
|
||||
twitter { '' }
|
||||
website { '' }
|
||||
address { '4 McDougal Rd' }
|
||||
city { 'Austinvale' }
|
||||
postcode { '2312' }
|
||||
state { Spree::State.find_by_name('Victoria') }
|
||||
country { Spree::Country.find_by_name('Australia') }
|
||||
end
|
||||
|
||||
Spree::Distributor.blueprint do
|
||||
name { "Distributor" }
|
||||
contact { "Mr Turing"}
|
||||
phone { "1000100100" }
|
||||
description { 'The creator' }
|
||||
email { 'alan@somewhere.com' }
|
||||
pickup_address { 'Wilmslow' }
|
||||
pickup_times{ "Whenever you're free" }
|
||||
city { 'Cheshire' }
|
||||
post_code { '2312' }
|
||||
state { Spree::State.find_by_name('Victoria') }
|
||||
country { Spree::Country.find_by_name('Australia') }
|
||||
end
|
||||
|
||||
Spree::Product.blueprint do
|
||||
name { "Apples" }
|
||||
description { 'Tasty apples' }
|
||||
available_on{ Date.today - 2.days }
|
||||
count_on_hand { 5 }
|
||||
price { 10.99 }
|
||||
distributors{[Spree::Distributor.first || Spree::Distributor.make]}
|
||||
end
|
||||
|
||||
Spree::Variant.blueprint do
|
||||
sku { "12345" }
|
||||
price { 10.99 }
|
||||
cost_price { 10.99 }
|
||||
end
|
||||
|
||||
Spree::Zone.blueprint do
|
||||
name {"Australia"}
|
||||
description {"Australia"}
|
||||
default_tax { true }
|
||||
end
|
||||
|
||||
Spree::ShippingMethod.blueprint do
|
||||
name {"Eeaterprises"}
|
||||
calculator_type { 'Spree::Calculator::FlatPercentItemTotal' }
|
||||
end
|
||||
|
||||
Spree::PaymentMethod.blueprint do
|
||||
name { "Bogus " }
|
||||
description { "" }
|
||||
environment { "test" }
|
||||
type { "Spree::Gateway::BogusSimple" }
|
||||
active { true }
|
||||
end
|
||||
36
spec/support/factories.rb
Normal file
36
spec/support/factories.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'faker'
|
||||
require 'spree/core/testing_support/factories'
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :supplier, :class => Spree::Supplier do
|
||||
sequence(:name) { |n| "Supplier #{n}" }
|
||||
description 'supplier'
|
||||
email 'supplier@example.com'
|
||||
address '4 McDougal Rd'
|
||||
city 'Austinvale'
|
||||
postcode '2312'
|
||||
state Spree::State.find_by_name('Victoria')
|
||||
country Spree::Country.find_by_name('Australia')
|
||||
end
|
||||
|
||||
factory :distributor, :class => Spree::Distributor do
|
||||
sequence(:name) { |n| "Distributor #{n}" }
|
||||
contact "Mr Turing"
|
||||
phone "1000100100"
|
||||
description 'The creator'
|
||||
email 'alan@somewhere.com'
|
||||
pickup_address 'Wilmslow'
|
||||
pickup_times "Whenever you're free"
|
||||
city 'Cheshire'
|
||||
post_code '2312'
|
||||
state Spree::State.find_by_name('Victoria')
|
||||
country Spree::Country.find_by_name('Australia')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
FactoryGirl.modify do
|
||||
factory :simple_product do
|
||||
distributors { [Spree::Distributor.first || FactoryGirl.create(:distributor)] }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user