Browse Source

Adding better fake seed data

topic-sass
Jason Denney 11 years ago
parent
commit
d0b2144b28
  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 'factory_girl_rails', '~> 1.2'
gem 'pry', '~> 0.9.8'
gem 'faker'
end
group :test do

3
Gemfile.lock

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

15
db/seeds.rb

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

22
spec/factories/bikes.rb

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

12
spec/factories/user_profiles.rb

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

1
spec/factories/users.rb

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

Loading…
Cancel
Save