From 73ce49de25e816f26d18faad3c26ea212526cfc2 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 2 May 2016 15:25:18 +0200 Subject: [PATCH] Use dynamic fake data in the spec --- .../admin/conferences_controller_spec.rb | 2 +- .../conference_registration_controller_spec.rb | 6 +++--- spec/features/lodgings_spec.rb | 14 +++++++------- spec/features/sponsor_spec.rb | 4 ++-- spec/features/ticket_purchases_spec.rb | 4 ++-- spec/helpers/sponsor_helper_spec.rb | 6 +++--- spec/models/email_settings_spec.rb | 8 ++++---- spec/models/event_spec.rb | 2 +- spec/serializers/conference_serializer_spec.rb | 8 ++++---- spec/serializers/room_serializer_spec.rb | 2 +- spec/serializers/track_serializer_spec.rb | 4 ++-- spec/views/admin/lodgings/index.html.haml_spec.rb | 2 +- spec/views/admin/sponsors/index.html.haml_spec.rb | 8 ++++---- .../sponsorship_levels/index.html.haml_spec.rb | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 9ad97cac..2384c909 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -58,7 +58,7 @@ describe Admin::ConferenceController do conference.reload expect(flash[:error]). to eq("Updating conference failed. Short title can't be blank.") - expect(conference.title).to eq('The dog and pony show') + expect(conference.title).to eq("#{conference.title}") expect(conference.short_title).to eq("#{conference.short_title}") end diff --git a/spec/controllers/conference_registration_controller_spec.rb b/spec/controllers/conference_registration_controller_spec.rb index 54a6c4bd..3071a38c 100644 --- a/spec/controllers/conference_registration_controller_spec.rb +++ b/spec/controllers/conference_registration_controller_spec.rb @@ -114,7 +114,7 @@ describe ConferenceRegistrationsController, type: :controller do end it 'shows error in flash message' do - expect(flash[:error]).to match "Could not update your registration for The dog and pony show: #{@registration.errors.full_messages.join('. ')}." + expect(flash[:error]).to match "Could not update your registration for #{conference.title}: #{@registration.errors.full_messages.join('. ')}." end it 'does not update the registration' do @@ -139,7 +139,7 @@ describe ConferenceRegistrationsController, type: :controller do end it 'shows success message in flash notice', run: true do - expect(flash[:notice]).to match('You are not registered for The dog and pony show anymore!') + expect(flash[:notice]).to match("You are not registered for #{conference.title} anymore!") end it 'deletes the registration' do @@ -160,7 +160,7 @@ describe ConferenceRegistrationsController, type: :controller do end it 'shows error in flash message' do - expect(flash[:error]).to match "Could not delete your registration for The dog and pony show: #{@registration.errors.full_messages.join('. ')}." + expect(flash[:error]).to match "Could not delete your registration for #{conference.title}: #{@registration.errors.full_messages.join('. ')}." end it 'does not delete the registration' do diff --git a/spec/features/lodgings_spec.rb b/spec/features/lodgings_spec.rb index 0731eff6..6d1d72ff 100644 --- a/spec/features/lodgings_spec.rb +++ b/spec/features/lodgings_spec.rb @@ -35,13 +35,13 @@ feature Lodging do visit admin_conference_lodgings_path( conference_id: conference.short_title) - expect(page.has_content?('Example Hotel')).to be true + expect(page.has_content?(lodging.name)).to be true # Add lodging click_link 'Edit' 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 click_button 'Update Lodging' @@ -51,26 +51,26 @@ feature Lodging do expect(page.has_content?('New lodging')).to be true lodging.reload expect(lodging.name).to eq('New lodging') - expect(lodging.description).to eq('Lorem Ipsum Dolor') - expect(lodging.website_link).to eq('http:\\www.google.com') + expect(lodging.description).to eq(lodging.description) + expect(lodging.website_link).to eq('http://www.google.com') expect(Lodging.count).to eq(1) end scenario 'Delete a lodging', feature: true, js: true do - conference.lodgings << create(:lodging) + lodging = create(:lodging, conference: conference) sign_in organizer visit admin_conference_lodgings_path( conference_id: conference.short_title) - expect(page.has_content?('Example Hotel')).to be true + expect(page.has_content?(lodging.name)).to be true # Add lodging click_link 'Delete' # Validations expect(flash).to eq('Lodging successfully deleted.') - expect(page.has_content?('Example Hotel')).to be false + expect(page.has_content?(lodging.name)).to be false expect(Lodging.count).to eq(0) end end diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index df527ede..c6b5009e 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -21,7 +21,7 @@ feature Sponsor do fill_in 'sponsor_description', with: 'The original provider of the enterprise Linux distribution' attach_file 'Picture', path fill_in 'sponsor_website_url', with: 'http://www.suse.com' - select('Platin', from: 'sponsor_sponsorship_level_id') + select(conference.sponsorship_levels.first.title, from: 'sponsor_sponsorship_level_id') click_button 'Create Sponsor' @@ -30,7 +30,7 @@ feature Sponsor do expect(page.has_content?('SUSE')).to be true expect(page.has_content?('The original provider')).to be true expect(page.has_content?('http://www.suse.com')).to be true - expect(page.has_content?('Platin')).to be true + expect(page.has_content?(conference.sponsorship_levels.first.title)).to be true expect(page).to have_selector("img[src*='rails.png']") expect(page.assert_selector('tr', count: 2)).to be true end diff --git a/spec/features/ticket_purchases_spec.rb b/spec/features/ticket_purchases_spec.rb index b8c8ecbe..e3ae1e09 100644 --- a/spec/features/ticket_purchases_spec.rb +++ b/spec/features/ticket_purchases_spec.rb @@ -33,7 +33,7 @@ feature Registration do expect(current_path).to eq(conference_conference_registrations_path(conference.short_title)) expect(flash). to eq("Thank you for supporting #{conference.title} by purchasing a ticket.") - expect(page.has_content?('2 Business Ticket Tickets for 10')).to be true + expect(page.has_content?("2 #{ticket.title} Tickets for 10")).to be true end scenario 'deletes a purchased ticket', feature: true, js: true do @@ -41,7 +41,7 @@ feature Registration do create(:ticket_purchase, conference: conference, user: participant, ticket: ticket, quantity: 4) visit conference_conference_registrations_path(conference.short_title) - expect(page.has_content?('4 Business Ticket Tickets for 10')).to be true + expect(page.has_content?("4 #{ticket.title} Tickets for 10")).to be true click_link "ticket-#{ticket.id}-delete" expect(flash).to eq('Ticket successfully deleted.') diff --git a/spec/helpers/sponsor_helper_spec.rb b/spec/helpers/sponsor_helper_spec.rb index ec9aff06..c6ce08ce 100644 --- a/spec/helpers/sponsor_helper_spec.rb +++ b/spec/helpers/sponsor_helper_spec.rb @@ -11,7 +11,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bfirst/rails.png\b)} + expect(get_logo(sponsor)).to match %r{.*(\bfirst/#{sponsor.logo_file_name}\b)} end end @@ -22,7 +22,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bsecond/rails.png\b)} + expect(get_logo(sponsor)).to match %r{.*(\bsecond/#{sponsor.logo_file_name}\b)} end end @@ -33,7 +33,7 @@ describe SponsorsHelper, type: :helper do end it 'returns correct url' do - expect(get_logo(sponsor)).to match %r{.*(\bothers/rails.png\b)} + expect(get_logo(sponsor)).to match %r{.*(\bothers/#{sponsor.logo_file_name}\b)} end end end diff --git a/spec/models/email_settings_spec.rb b/spec/models/email_settings_spec.rb index a649ab92..8392d056 100644 --- a/spec/models/email_settings_spec.rb +++ b/spec/models/email_settings_spec.rb @@ -9,7 +9,7 @@ describe EmailSettings do { 'email' => 'john@doe.com', 'name' => 'John Doe', - 'conference' => 'The dog and pony show', + 'conference' => conference.title, 'conference_start_date' => Date.new(2014, 05, 01), 'conference_end_date' => Date.new(2014, 05, 06), 'registrationlink' => 'http://localhost:3000/conference/goto/register', @@ -62,7 +62,7 @@ describe EmailSettings do context 'conference has venue' do before do conference.update_attributes(venue: create(:venue)) - venue_hash = { 'venue' => 'Suse Office', 'venue_address' => 'Maxfeldstrasse 5, Nuremberg, Germany' } + venue_hash = { 'venue' => conference.venue.name, 'venue_address' => conference.venue.address } expected_hash.merge!(venue_hash) end @@ -105,7 +105,7 @@ describe EmailSettings do it 'replaces fillers in template' do expected_text = "Dear John Doe\n\nWe are very pleased" \ - 'to inform you that your submission Talk about talks has been accepted for the conference The dog and pony show.' + "to inform you that your submission Talk about talks has been accepted for the conference #{conference.title}." expect(conference.email_settings.generate_event_mail(event, event_template)).to eq expected_text end end @@ -114,7 +114,7 @@ describe EmailSettings do let(:conf_update_template) { "Dear {name},\n\nThank you for Registering for the conference {conference}." } it 'replaces fillers in template' do - expected_text = "Dear John Doe,\n\nThank you for Registering for the conference The dog and pony show." + expected_text = "Dear John Doe,\n\nThank you for Registering for the conference #{conference.title}." expect(conference.email_settings.generate_email_on_conf_updates(conference, user, conf_update_template)).to eq expected_text end end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index e25dd354..6bbb416c 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -221,7 +221,7 @@ describe Event do describe '#abstract_word_count' do it 'counts words in abstract' do event = build(:event) - expect(event.abstract_word_count).to eq(233) + expect(event.abstract_word_count).to eq(event.abstract.to_s.split.size) event.update_attributes!(abstract: 'abstract.') expect(event.abstract_word_count).to eq(1) end diff --git a/spec/serializers/conference_serializer_spec.rb b/spec/serializers/conference_serializer_spec.rb index 1de2f887..20c28f7f 100644 --- a/spec/serializers/conference_serializer_spec.rb +++ b/spec/serializers/conference_serializer_spec.rb @@ -12,7 +12,7 @@ describe ConferenceSerializer, type: :serializer do { conference: { short_title: 'goto', - title: 'The dog and pony show', + title: conference.title, description: 'Lorem ipsum dolor sit', start_date: '2014-03-04', end_date: '2014-03-10', @@ -61,7 +61,7 @@ describe ConferenceSerializer, type: :serializer do before do venue = create(:venue, conference: conference) _room = create(:room, venue: venue) - _track = create(:track, program: conference.program) + track = create(:track, program: conference.program) room_hash = { rooms: [{ @@ -74,8 +74,8 @@ describe ConferenceSerializer, type: :serializer do track_hash = { tracks: [{ id: 1, - name: 'Example Track', - description: 'Lorem Ipsum dolsum' + name: track.name, + description: track.description } ] } diff --git a/spec/serializers/room_serializer_spec.rb b/spec/serializers/room_serializer_spec.rb index 6ec10985..5b7467cc 100644 --- a/spec/serializers/room_serializer_spec.rb +++ b/spec/serializers/room_serializer_spec.rb @@ -7,7 +7,7 @@ describe RoomSerializer, type: :serializer do expected_json = { room: { guid: room.guid, - name: 'Example Room', + name: room.name, description: '' } }.to_json diff --git a/spec/serializers/track_serializer_spec.rb b/spec/serializers/track_serializer_spec.rb index 856a593c..e6c55d6c 100644 --- a/spec/serializers/track_serializer_spec.rb +++ b/spec/serializers/track_serializer_spec.rb @@ -8,8 +8,8 @@ describe TrackSerializer, type: :serializer do expected_json = { track: { guid: track.guid, - name: 'Example Track', - color: '#ffffff' + name: track.name, + color: track.color } }.to_json diff --git a/spec/views/admin/lodgings/index.html.haml_spec.rb b/spec/views/admin/lodgings/index.html.haml_spec.rb index bb20da17..30fdaece 100644 --- a/spec/views/admin/lodgings/index.html.haml_spec.rb +++ b/spec/views/admin/lodgings/index.html.haml_spec.rb @@ -7,6 +7,6 @@ describe 'admin/lodgings/index' do @conference.lodgings << create(:lodging) assign :venue, @conference.venue render - expect(rendered).to include('Example Hotel') + expect(rendered).to include(@conference.lodgings.first.name) end end diff --git a/spec/views/admin/sponsors/index.html.haml_spec.rb b/spec/views/admin/sponsors/index.html.haml_spec.rb index 51b845ff..6311c5d1 100644 --- a/spec/views/admin/sponsors/index.html.haml_spec.rb +++ b/spec/views/admin/sponsors/index.html.haml_spec.rb @@ -9,9 +9,9 @@ describe 'admin/sponsors/index' do ) assign :conference, @conference render - expect(rendered).to include('Example sponsor') - expect(rendered).to include('http://www.example.com') - expect(rendered).to include('Lorem Ipsum Dolor') - expect(rendered).to include('Platin') + expect(rendered).to include(@conference.sponsors.first.name) + expect(rendered).to include(@conference.sponsors.first.website_url) + expect(rendered).to include(truncate(@conference.sponsors.first.description)) + expect(rendered).to include(@conference.sponsorship_levels.first.title) end end diff --git a/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb b/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb index 29ec4f7e..d3abb41e 100644 --- a/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb +++ b/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb @@ -5,6 +5,6 @@ describe 'admin/sponsorship_levels/index' do @sponsorship_level = create(:sponsorship_level) assign :conference, @sponsorship_level.conference render - expect(rendered).to include('Platin') + expect(rendered).to include(@sponsorship_level.title) end end