add some rspec tests for supplier and article

This commit is contained in:
wvengen 2013-07-14 02:49:40 +02:00
parent 7fa8193010
commit 3c264f6225
8 changed files with 110 additions and 2 deletions

20
spec/factories/article.rb Normal file
View file

@ -0,0 +1,20 @@
require 'factory_girl'
FactoryGirl.define do
factory :article do
name { Faker::Lorem.words(rand(2..5)).join(' ') }
unit { Faker::Unit.unit }
price { rand(2600) / 100 }
tax { [6, 21].sample }
deposit { rand(10) < 8 ? 0 : [0.0, 0.80, 1.20, 12.00].sample }
unit_quantity { rand(5) < 3 ? 1 : rand(1..20) }
#supplier_id
article_category { FactoryGirl.create :article_category }
end
factory :article_category do
name { Faker::Lorem.characters(rand(2..20)) }
end
end

View file

@ -0,0 +1,19 @@
require 'factory_girl'
FactoryGirl.define do
factory :supplier do
name { Faker::Company.name }
phone { Faker::PhoneNumber.phone_number }
address { Faker::Address.street_address }
ignore do
article_count 0
end
after :create do |supplier, evaluator|
FactoryGirl.create_list :article, evaluator.article_count, supplier: supplier
end
end
end

View file

@ -4,8 +4,8 @@ FactoryGirl.define do
factory :user do
sequence(:nick) { |n| "user#{n}"}
first_name 'John'
email { "#{nick}@foodcoop.test" }
first_name { Faker::Name.first_name }
email { Faker::Internet.email }
password { new_random_password }
factory :admin do