Browse Source

Merge pull request #94 from spacemunkay/denney-add-faker-data

Denney add faker data
topic-sass
Jason Denney 11 years ago
parent
commit
85129dccaa
  1. 1
      Gemfile
  2. 3
      Gemfile.lock
  3. 15
      db/seeds.rb
  4. 22
      spec/factories/bikes.rb
  5. 12
      spec/factories/user_profiles.rb
  6. 1
      spec/factories/users.rb

1
Gemfile

@ -33,6 +33,7 @@ group :development, :test do
gem 'rspec-rails', '~> 2.8.1' gem 'rspec-rails', '~> 2.8.1'
gem 'factory_girl_rails', '~> 1.2' gem 'factory_girl_rails', '~> 1.2'
gem 'pry', '~> 0.9.8' gem 'pry', '~> 0.9.8'
gem 'faker'
end end
group :test do group :test do

3
Gemfile.lock

@ -77,6 +77,8 @@ GEM
factory_girl_rails (1.7.0) factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0) factory_girl (~> 2.6.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.2.0)
i18n (~> 0.5)
ffi (1.6.0) ffi (1.6.0)
formatador (0.2.4) formatador (0.2.4)
gherkin (2.11.6) gherkin (2.11.6)
@ -231,6 +233,7 @@ DEPENDENCIES
decent_exposure (~> 1.0.1) decent_exposure (~> 1.0.1)
devise (~> 2.0.4) devise (~> 2.0.4)
factory_girl_rails (~> 1.2) factory_girl_rails (~> 1.2)
faker
guard-rspec guard-rspec
guard-spork guard-spork
haml-rails (~> 0.3.4) haml-rails (~> 0.3.4)

15
db/seeds.rb

@ -26,13 +26,16 @@ end
if Rails.env.development? if Rails.env.development?
#create default admin user #create default users
if User.all.empty? if User.all.empty?
FactoryGirl.create(:user) u = FactoryGirl.create(:user)
FactoryGirl.create(:staff) FactoryGirl.create(:user_profile, user_id: u.id)
FactoryGirl.create(:bike_admin) u = FactoryGirl.create(:staff)
FactoryGirl.create(:admin) FactoryGirl.create(:user_profile, user_id: u.id)
FactoryGirl.create(:user_profile) u = FactoryGirl.create(:bike_admin)
FactoryGirl.create(:user_profile, user_id: u.id)
u = FactoryGirl.create(:admin)
FactoryGirl.create(:user_profile, user_id: u.id)
end end
#create fake bikes #create fake bikes

22
spec/factories/bikes.rb

@ -4,17 +4,17 @@ FactoryGirl.define do
factory :bike do factory :bike do
sequence(:shop_id) {|n| n} sequence(:shop_id) {|n| n}
sequence :serial_number do |n| sequence :serial_number do |n|
"S/N# #{n}" "#{Faker::Code.isbn}-#{n}"
end end
bike_brand_id 1 bike_brand_id { BikeBrand.all.sample.id }
bike_model_id 1 model { Faker::Commerce.product_name }
color "FFFFFF" color { sprintf("%06X", Random.rand(16777215) ) }
bike_style_id 1 bike_style_id { BikeStyle.all.sample.id }
seat_tube_height 5 seat_tube_height { Random.rand(25) }
top_tube_length 6 top_tube_length { Random.rand(25) }
bike_wheel_size_id 1 bike_wheel_size_id { BikeWheelSize.all.sample.id }
value 100 value { Random.rand(200) }
bike_condition_id 1 bike_condition_id { BikeCondition.all.sample.id }
bike_purpose_id 1 bike_purpose_id { BikePurpose.all.sample.id }
end end
end end

12
spec/factories/user_profiles.rb

@ -1,11 +1,11 @@
FactoryGirl.define do FactoryGirl.define do
factory :user_profile do factory :user_profile do
user_id 1 user_id 1
addrStreet1 "Charles Street" addrStreet1 { Faker::Address.street_address }
addrStreet2 "Apt #42" addrStreet2 { Faker::Address.secondary_address }
addrCity "Baltimore" addrCity { Faker::Address.city }
addrState "MD" addrState { Faker::Address.state_abbr }
addrZip "21231" addrZip { Faker::Address.zip_code }
phone "(410)8675309" phone { Faker::PhoneNumber.cell_phone }
end end
end end

1
spec/factories/users.rb

@ -1,5 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
sequence(:username) { |n| "user_#{n}" } sequence(:username) { |n| "user_#{n}" }
sequence(:email) { |n| "user_#{n}@example.com" } sequence(:email) { |n| "user_#{n}@example.com" }
password 'password' password 'password'

Loading…
Cancel
Save