Merge pull request #985 from hennevogel/feature_factories

Some fixes for review apps
This commit is contained in:
Christian Bruckmayer 2016-05-12 12:49:47 +02:00
commit 3d2e1f3219
16 changed files with 40 additions and 35 deletions

View file

@ -7,7 +7,14 @@ class PictureUploader < CarrierWave::Uploader::Base
# use cloudinary if it's configured # use cloudinary if it's configured
if Cloudinary.config.cloud_name if Cloudinary.config.cloud_name
# use https by default
Cloudinary.config.secure = true
include Cloudinary::CarrierWave include Cloudinary::CarrierWave
def public_id
model.try(:photo_file_name) || model.try(:logo_file_name)
end
end end
def paperclip_path def paperclip_path

View file

@ -2,7 +2,9 @@ namespace :data do
desc 'Create demo data using our factories' desc 'Create demo data using our factories'
task demo: :environment do task demo: :environment do
include FactoryGirl::Syntax::Methods include FactoryGirl::Syntax::Methods
create(:full_conference)
create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password', password_confirmation: 'password') conference = create(:full_conference, title: 'Open Source Event Manager Demo', short_title: 'osemdemo' ,description: "This is a [Open Source Event Manager](http://osem.io/) demo instance. You can log in as **admin** with the password **password123** or just you just [sign up](/accounts/sign_up) with your own user. We hope you enjoy checking out all the functionality, if you have questions don't hesitate to [contact us](http://osem.io/#contact)!\r\n\r\n## Data will be destroyed every thirty minutes or whenever someone updates the [OSEM source code on github](https://github.com/openSUSE/osem/commits/master).")
conference.contact.update_attributes(email: 'osemdemo@osem.io', sponsor_email: 'osemdemo@osem.io')
create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password123', password_confirmation: 'password123')
end end
end end

View file

@ -8,7 +8,7 @@ FactoryGirl.define do
start_date { Date.today } start_date { Date.today }
end_date { 6.days.from_now } end_date { 6.days.from_now }
registration_limit 0 registration_limit 0
description { CGI.escapeHTML(Faker::Hipster.paragraph) } description { Faker::Hipster.paragraph }
after(:create) do |conference| 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)') Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)')
@ -46,10 +46,10 @@ FactoryGirl.define do
create(:question, conferences: [conference]) create(:question, conferences: [conference])
# Logo... # Logo...
uploader = PictureUploader.new(conference, :picture) File.open('spec/support/logos/OSEM.jpg') do |file|
File.open('app/assets/images/rails.png') { |f| uploader.store!(f) } conference.picture = file
conference.logo_file_name = 'rails.png' end
conference.save conference.save!
end end
end end
end end

View file

@ -30,6 +30,5 @@ FactoryGirl.define do
event.comment_threads << build(:comment, commentable: event) event.comment_threads << build(:comment, commentable: event)
end end
end end
end end
end end

View file

@ -3,7 +3,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :lodging do factory :lodging do
name { "#{Faker::App.name} Hotel" } name { "#{Faker::App.name} Hotel" }
description { CGI.escapeHTML(Faker::Lorem.paragraph) } description { Faker::Lorem.paragraph }
website_link { Faker::Internet.url } website_link { Faker::Internet.url }
end end
end end

View file

@ -4,16 +4,15 @@ FactoryGirl.define do
factory :sponsor do factory :sponsor do
name { Faker::Company.name } name { Faker::Company.name }
website_url { Faker::Internet.url } website_url { Faker::Internet.url }
description { CGI.escapeHTML(Faker::Lorem.paragraph) } description { Faker::Lorem.paragraph }
sponsorship_level sponsorship_level
after(:create) do |sponsor| after(:create) do |sponsor|
logo = "#{1 + rand(13)}.png" File.open("spec/support/logos/#{1 + rand(13)}.png") do |file|
uploader = PictureUploader.new(sponsor, :picture) sponsor.picture = file
File.open("spec/support/logos/#{logo}") { |f| uploader.store!(f) } end
sponsor.logo_file_name = logo.to_s sponsor.save!
sponsor.save
end end
end end
end end

View file

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

View file

@ -8,7 +8,5 @@ FactoryGirl.define do
country { Faker::Address.country_code } country { Faker::Address.country_code }
website { Faker::Internet.url } website { Faker::Internet.url }
description { Faker::Lorem.sentence } description { Faker::Lorem.sentence }
conference
end end
end end

View file

@ -15,7 +15,7 @@ feature Lodging do
click_link 'Add Lodging' click_link 'Add Lodging'
fill_in 'lodging_name', with: 'New lodging' fill_in 'lodging_name', with: 'New lodging'
fill_in 'lodging_website_link', with: 'http:\\www.google.com' fill_in 'lodging_website_link', with: 'http://www.google.com'
attach_file 'Picture', path attach_file 'Picture', path
click_button 'Create Lodging' click_button 'Create Lodging'
@ -35,7 +35,7 @@ feature Lodging do
visit admin_conference_lodgings_path( visit admin_conference_lodgings_path(
conference_id: conference.short_title) conference_id: conference.short_title)
expect(page.has_content?(lodging.name)).to be true expect(page.has_content?(CGI.escapeHTML(lodging.name))).to be true
# Add lodging # Add lodging
click_link 'Edit' click_link 'Edit'
@ -51,7 +51,7 @@ feature Lodging do
expect(page.has_content?('New lodging')).to be true expect(page.has_content?('New lodging')).to be true
lodging.reload lodging.reload
expect(lodging.name).to eq('New lodging') expect(lodging.name).to eq('New lodging')
expect(lodging.description).to eq(lodging.description) expect(lodging.description).to eq(CGI.escapeHTML(lodging.description))
expect(lodging.website_link).to eq('http://www.google.com') expect(lodging.website_link).to eq('http://www.google.com')
expect(Lodging.count).to eq(1) expect(Lodging.count).to eq(1)
end end
@ -70,7 +70,7 @@ feature Lodging do
# Validations # Validations
expect(flash).to eq('Lodging successfully deleted.') expect(flash).to eq('Lodging successfully deleted.')
expect(page.has_content?(lodging.name)).to be false expect(page.has_content?(CGI.escapeHTML(lodging.name))).to be false
expect(Lodging.count).to eq(0) expect(Lodging.count).to eq(0)
end end
end end

BIN
spec/support/logos/OSEM.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -8,6 +8,6 @@ describe 'admin/conference/index' do
assign(:conferences, [conference, second_conference]) assign(:conferences, [conference, second_conference])
render render
expect(rendered).to include('openSUSE Conference 2016') expect(rendered).to include('openSUSE Conference 2016')
expect(rendered).to include(second_conference.title) expect(rendered).to include(CGI.escapeHTML(second_conference.title))
end end
end end

View file

@ -9,6 +9,6 @@ describe 'admin/conference/new' do
expect(rendered).to include('Basic Information') expect(rendered).to include('Basic Information')
assign(:conference, conference) assign(:conference, conference)
render render
expect(rendered).to include(conference.title) expect(rendered).to include(CGI.escapeHTML(conference.title))
end end
end end

View file

@ -7,6 +7,6 @@ describe 'admin/lodgings/index' do
@conference.lodgings << create(:lodging) @conference.lodgings << create(:lodging)
assign :venue, @conference.venue assign :venue, @conference.venue
render render
expect(rendered).to include(@conference.lodgings.first.name) expect(rendered).to include(CGI.escapeHTML(@conference.lodgings.first.name))
end end
end end

View file

@ -9,9 +9,9 @@ describe 'admin/sponsors/index' do
) )
assign :conference, @conference assign :conference, @conference
render render
expect(rendered).to include(@conference.sponsors.first.name) expect(rendered).to include(CGI.escapeHTML(@conference.sponsors.first.name))
expect(rendered).to include(@conference.sponsors.first.website_url) expect(rendered).to include(@conference.sponsors.first.website_url)
expect(rendered).to include(truncate(@conference.sponsors.first.description)) expect(rendered).to include(truncate(CGI.escapeHTML(@conference.sponsors.first.description)))
expect(rendered).to include(@conference.sponsorship_levels.first.title) expect(rendered).to include(CGI.escapeHTML(@conference.sponsorship_levels.first.title))
end end
end end

View file

@ -5,6 +5,6 @@ describe 'admin/sponsorship_levels/index' do
@sponsorship_level = create(:sponsorship_level) @sponsorship_level = create(:sponsorship_level)
assign :conference, @sponsorship_level.conference assign :conference, @sponsorship_level.conference
render render
expect(rendered).to include(@sponsorship_level.title) expect(rendered).to include(CGI.escapeHTML(@sponsorship_level.title))
end end
end end

View file

@ -9,7 +9,7 @@ describe 'conference/show.html.haml' do
end end
it 'renders banner component' do it 'renders banner component' do
expect(rendered).to match(conference.description) expect(rendered).to match(CGI.escapeHTML(conference.description))
end end
it 'renders program partial' do it 'renders program partial' do
@ -28,7 +28,7 @@ describe 'conference/show.html.haml' do
expect(view).to render_template(partial: 'conference/_sponsors') expect(view).to render_template(partial: 'conference/_sponsors')
expect(rendered).to match(conference.contact.email) expect(rendered).to match(conference.contact.email)
expect(rendered).to match(conference.sponsors.first.website_url) expect(rendered).to match(conference.sponsors.first.website_url)
expect(rendered).to match(conference.sponsors.first.description) expect(rendered).to match(CGI.escapeHTML(conference.sponsors.first.description))
expect(rendered).to match(conference.sponsors.first.logo_file_name) expect(rendered).to match(conference.sponsors.first.logo_file_name)
end end
@ -42,16 +42,16 @@ describe 'conference/show.html.haml' do
it 'renders venue partial' do it 'renders venue partial' do
expect(view).to render_template(partial: 'conference/_venue') expect(view).to render_template(partial: 'conference/_venue')
expect(rendered).to match(conference.venue.name) expect(rendered).to match(CGI.escapeHTML(conference.venue.name))
expect(rendered).to match(conference.venue.street) expect(rendered).to match(conference.venue.street)
expect(rendered).to match(conference.venue.website) expect(rendered).to match(conference.venue.website)
expect(rendered).to match(conference.venue.description) expect(rendered).to match(CGI.escapeHTML(conference.venue.description))
end end
it 'renders lodging partial' do it 'renders lodging partial' do
expect(view).to render_template(partial: 'conference/_lodging') expect(view).to render_template(partial: 'conference/_lodging')
expect(rendered).to match(conference.lodgings.first.name) expect(rendered).to match(CGI.escapeHTML(conference.lodgings.first.name))
expect(rendered).to match(conference.lodgings.first.description) expect(rendered).to match(CGI.escapeHTML(conference.lodgings.first.description))
# FIXME: Lodging without image doesn't show link # FIXME: Lodging without image doesn't show link
# expect(rendered).to match(conference.lodgings.first.website_link) # expect(rendered).to match(conference.lodgings.first.website_link)
end end