diff --git a/Gemfile b/Gemfile index 7cf8cd07ac..1b83faf9a5 100644 --- a/Gemfile +++ b/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' diff --git a/Gemfile.lock b/Gemfile.lock index 1aa9bb4a74..53c36f0bb5 100644 --- a/Gemfile.lock +++ b/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) diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index c4fa936e32..eb87750b80 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -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 diff --git a/spec/requests/admin/product_spec.rb b/spec/requests/admin/product_spec.rb index 3d2c3ca7f2..6f06ceb0b4 100644 --- a/spec/requests/admin/product_spec.rb +++ b/spec/requests/admin/product_spec.rb @@ -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 diff --git a/spec/requests/consumer/checkout_spec.rb b/spec/requests/consumer/checkout_spec.rb index 57bae7846e..1c588dcb2d 100644 --- a/spec/requests/consumer/checkout_spec.rb +++ b/spec/requests/consumer/checkout_spec.rb @@ -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 diff --git a/spec/requests/consumer/distributors_spec.rb b/spec/requests/consumer/distributors_spec.rb index d0038298a1..32ba524488 100644 --- a/spec/requests/consumer/distributors_spec.rb +++ b/spec/requests/consumer/distributors_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b04e353bbb..1384272fa4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -60,6 +60,7 @@ Spork.prefork do end config.include Spree::UrlHelpers + config.include FactoryGirl::Syntax::Methods end end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb deleted file mode 100644 index 279df8338d..0000000000 --- a/spec/support/blueprints.rb +++ /dev/null @@ -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 diff --git a/spec/support/factories.rb b/spec/support/factories.rb new file mode 100644 index 0000000000..282c084b33 --- /dev/null +++ b/spec/support/factories.rb @@ -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