Make use of fake data in factories

This commit is contained in:
Henne Vogelsang 2016-04-30 17:56:23 +02:00
parent 737a9d4808
commit 77e0340387
30 changed files with 96 additions and 77 deletions

View file

@ -3,8 +3,6 @@ class Contact < ActiveRecord::Base
validates :conference, presence: true
# Conferences only have one contact
validates :conference_id, uniqueness: {message: 'has already contact details'}
validates :facebook, :twitter, :googleplus, :instagram,
format: URI::regexp(%w(http https)), allow_blank: true

View file

@ -6,7 +6,6 @@ class Venue < ActiveRecord::Base
accepts_nested_attributes_for :commercial, allow_destroy: true
validates :name, :street, :city, :country, presence: true
validates :conference_id, presence: true, uniqueness: true
mount_uploader :picture, PictureUploader, mount_on: :photo_file_name
@ -32,7 +31,7 @@ class Venue < ActiveRecord::Base
end
def notify_on_venue_changed?
return false unless conference.email_settings.send_on_venue_updated
return false unless conference.try(:email_settings).try(:send_on_venue_updated)
# do not notify unless the address changed
return false unless self.name_changed? || self.street_changed? || self.city_changed? || self.country_changed?
# do not notify unless the mail content is set up

View file

@ -2,8 +2,9 @@
FactoryGirl.define do
factory :cfp do
program
start_date { 1.day.ago }
end_date { 6.days.from_now }
program
end
end

View file

@ -2,12 +2,13 @@
FactoryGirl.define do
factory :conference do
title 'The dog and pony show'
sequence(:short_title) { |n| "dps#{n}14" }
timezone 'Amsterdam'
title { Faker::Book.title }
short_title { SecureRandom.urlsafe_base64(4) }
timezone { Faker::Address.time_zone }
start_date { Date.today }
end_date { 6.days.from_now }
registration_limit 0
description { Faker::Hipster.paragraph }
after(:create) do |conference|
Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)')
@ -17,19 +18,38 @@ FactoryGirl.define do
end
factory :full_conference do
splashpage
association :splashpage, factory: :full_splashpage
registration_period
venue
after :create do |conference|
create(:venue, conference_id: conference.id)
conference.commercials << create(:conference_commercial, commercialable: conference)
conference.campaigns << create(:campaign, conference: conference)
conference.targets << create(:target, conference: conference)
conference.questions << create(:question, conference_id: conference.id)
conference.lodgings << create(:lodging, conference: conference)
conference.sponsors << create(:sponsor, conference: conference)
conference.sponsorship_levels << create(:sponsorship_level, conference: conference)
conference.tickets << create(:ticket, conference: conference)
# Contact/Program is created by Conference callbacks
conference.contact.destroy
conference.contact = create(:contact, conference: conference)
conference.program.update_attributes(schedule_public: true)
create(:cfp, program: conference.program)
create_list(:track, 2, program: conference.program)
create_list(:ticket, 3, conference: conference)
create_list(:room, 3, venue: conference.venue)
create_list(:lodging, 4, conference: conference)
create_list(:sponsorship_level, 3, conference: conference)
create(:sponsor, sponsorship_level: conference.sponsorship_levels.first, conference: conference)
create_list(:sponsor, 2, sponsorship_level: conference.sponsorship_levels.second, conference: conference)
create_list(:sponsor, 3, sponsorship_level: conference.sponsorship_levels.third, conference: conference)
create(:campaign, conference: conference)
create(:target, conference: conference)
create(:question, conferences: [conference])
# Logo...
uploader = PictureUploader.new(conference, :picture)
File.open('app/assets/images/rails.png') { |f| uploader.store!(f) }
conference.logo_file_name = 'rails.png'
conference.save
end
end
end

View file

@ -0,0 +1,13 @@
FactoryGirl.define do
factory :contact do
social_tag { SecureRandom.urlsafe_base64(4) }
email { Faker::Internet.email }
sponsor_email { Faker::Internet.email }
facebook { Faker::Internet.url('facebook.com') }
googleplus { Faker::Internet.url('plus.google.com') }
twitter { Faker::Internet.url('twitter.com') }
instagram { Faker::Internet.url('instagram.com') }
conference
end
end

View file

@ -2,34 +2,11 @@
FactoryGirl.define do
factory :event do
sequence(:title) { |n| "The ##{n} talk you'll ever attend." }
program
abstract <<-EOS
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ante
lacus, mollis non urna vitae, varius semper leo. Nulla ac nibh dui. Mauris
convallis diam eu porta fermentum. Vestibulum posuere odio et est ornare,
at consectetur ante eleifend. Etiam tellus libero, ornare at euismod nec,
luctus a leo. Aliquam et commodo lacus, at luctus nibh. Aenean eleifend
risus a nisi pellentesque tempor. Etiam dapibus facilisis odio at ornare.
Mauris tempus, nunc ut malesuada iaculis, eros mi mattis ligula, vitae
lobortis enim lacus ut nunc. Donec mattis sagittis imperdiet.
Pellentesque ultrices malesuada ipsum, mattis dignissim felis pulvinar
vitae. Etiam ultrices erat convallis arcu placerat, at vulputate felis
tempus. Ut eleifend sem et ante feugiat euismod ac luctus tortor. Nam
commodo mattis erat ac condimentum. Duis dictum tempus odio, quis
adipiscing justo. Etiam nunc neque, rutrum vitae sapien eget, elementum
dignissim dui.
title { Faker::Hipster.sentence }
abstract { Faker::Hipster.paragraph(2) }
program
Donec vitae laoreet augue. Sed eget felis placerat, scelerisque felis eu,
mattis risus. Sed posuere arcu at lacus ultricies pretium. Aenean in
dapibus erat. Morbi vitae risus eu ante lacinia mollis. Donec vitae
hendrerit est. Maecenas ac sem non mi vulputate aliquam ac eget enim.
Curabitur eget volutpat nisi. Proin sit amet consequat urna. Aliquam nec
elit vitae tellus pellentesque ultricies. Sed in enim vitae nisl
ullamcorper dignissim. Proin aliquet nisi sed mauris dapibus, sit amet
dignissim quam pulvinar. Nunc dictum porta sodales. Cras ullamcorper
libero quis porta ultricies. Fusce pulvinar accumsan lobortis.
EOS
after(:build) do |event|
event.event_users << build(:submitter) unless event.submitter # so that we don't have two submitters
# set an event_type if none is passed to the factory.

View file

@ -2,9 +2,8 @@
FactoryGirl.define do
factory :lodging do
name 'Example Hotel'
description 'Lorem Ipsum Dolor'
website_link 'http://www.example.com'
conference
name { "#{Faker::App.name} Hotel" }
description { Faker::Lorem.paragraph }
website_link { Faker::Internet.url }
end
end

View file

@ -2,11 +2,9 @@
FactoryGirl.define do
factory :question do
title 'blah'
title { Faker::Lorem.sentence }
question_type
after(:build) do |question|
question.answers << build(:answer)
question.conferences << build(:conference)
end
conferences { [create(:conference)] }
answers { [create(:answer) ] }
end
end

View file

@ -2,8 +2,7 @@
FactoryGirl.define do
factory :registration_period do
start_date { 3.days.from_now }
start_date { 3.days.ago }
end_date { 5.days.from_now }
conference
end
end

View file

@ -1,8 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :room do
name 'Example Room'
name { "Room #{Faker::Address.country}" }
size 4
venue
factory :room_for_100 do

View file

@ -3,5 +3,18 @@
FactoryGirl.define do
factory :splashpage do
public false
factory :full_splashpage do
public true
include_tracks true
include_program true
include_social_media true
include_venue true
include_tickets true
include_registrations true
include_sponsors true
include_lodgings true
include_cfp true
end
end
end

View file

@ -2,16 +2,17 @@
FactoryGirl.define do
factory :sponsor do
name 'Example sponsor'
website_url 'http://www.example.com'
description 'Lorem Ipsum Dolor'
name { Faker::Company.name }
website_url { Faker::Internet.url }
description { Faker::Lorem.paragraph }
sponsorship_level
conference
after(:create) do |sponsor|
logo = "#{1 + rand(13)}.png"
uploader = PictureUploader.new(sponsor, :picture)
File.open('app/assets/images/rails.png') { |f| uploader.store!(f) }
sponsor.logo_file_name = 'rails.png'
File.open("spec/support/logos/#{logo}") { |f| uploader.store!(f) }
sponsor.logo_file_name = logo.to_s
sponsor.save
end
end

View file

@ -2,7 +2,8 @@
FactoryGirl.define do
factory :sponsorship_level do
title 'Platin'
title { Faker::Hipster.word }
conference
end
end

View file

@ -1,8 +1,7 @@
FactoryGirl.define do
factory :ticket do
title 'Business Ticket'
title { "#{Faker::Hipster.word} Ticket" }
price_cents 1000
price_currency 'USD'
conference
end
end

View file

@ -1,9 +1,7 @@
FactoryGirl.define do
factory :track do
name 'Example Track'
description 'Lorem Ipsum dolsum'
color '#ffffff'
program
name { Faker::Commerce.department(2, true) }
description { Faker::Lorem.sentence }
color { Faker::Color.hex_color }
end
end

View file

@ -1,13 +1,14 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :venue do
name 'Suse Office'
street 'Maxfeldstrasse 5'
city 'Nuremberg'
postalcode '90489'
country 'DE'
website 'www.opensuse.org'
description 'Lorem Ipsum Dolor'
name { "#{Faker::Company.name} Office" }
street { Faker::Address.street_address }
city { Faker::Address.city }
postalcode { Faker::Address.postcode }
country { Faker::Address.country_code }
website { Faker::Internet.url }
description { Faker::Lorem.sentence }
conference
end
end

BIN
spec/support/logos/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
spec/support/logos/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

BIN
spec/support/logos/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
spec/support/logos/12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
spec/support/logos/13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
spec/support/logos/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
spec/support/logos/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
spec/support/logos/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
spec/support/logos/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
spec/support/logos/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
spec/support/logos/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
spec/support/logos/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
spec/support/logos/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View file

@ -0,0 +1 @@
These are fake logos from https://github.com/pigment/fake-logos