From 905f8954d05b344cf885990fd4009ae6e0ca1d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 17 Jun 2017 20:32:57 +0200 Subject: [PATCH] Fix broken test in Admin::EventsController We are using `paper_trail` gem, which saves data in database table versions. It has a native way to search in the versions records, using `where_object()` and `where_object_changes()`. They are broken, under certain conditions. We changed them to a manual `where()`. To test this case we need: an Event with ID 1, an Event with ID 2, and a commercial with ID 1, for event with ID 2 - obviously the numbers could be different as long as there is this matching of IDs. Before this was made wit ha expect, which would make the test fail if this is not the case. But this is actually the test case, not what we want to test, so I moved to the `let`. This was also the case why one of the test was broken after we change how the database is cleaned in: https://github.com/openSUSE/osem/pull/1541 I also remove the feature test, as this should be tested in a controller test. --- spec/controllers/admin/events_controller_spec.rb | 12 +++++++----- spec/features/versions_spec.rb | 2 -- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index a413ba7a..682defce 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -4,9 +4,13 @@ describe Admin::EventsController do let(:conference) { create(:conference) } let(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let(:organizer) { create(:user, role_ids: organizer_role.id) } - let!(:event_without_commercial) { create(:event, program: conference.program) } - let!(:event_with_commercial) { create(:event, program: conference.program) } - let!(:event_commercial) { create(:event_commercial, commercialable: event_with_commercial, url: 'https://www.youtube.com/watch?v=M9bq_alk-sw') } + # The where_object() and where_object_changes() methods of paper_trail gem are broken when having: + # an Event with ID 1, an Event with ID 2, and a commercial with ID 1, for event with ID 2 + # (the numbers could be different as long as there is this matching of IDs). + # We implemented or own where method to solve this and those ids are for testing this case. + let!(:event_without_commercial) { create(:event, id: 1, program: conference.program) } + let!(:event_with_commercial) { create(:event, id: 2, program: conference.program) } + let!(:event_commercial) { create(:event_commercial, id: 1, commercialable: event_with_commercial, url: 'https://www.youtube.com/watch?v=M9bq_alk-sw') } with_versioning do describe 'GET #show' do @@ -17,8 +21,6 @@ describe Admin::EventsController do it 'assigns versions' do versions = event_without_commercial.versions - expect(event_without_commercial.id).to eq event_commercial.id - expect(event_commercial.id).not_to eq event_commercial.commercialable_id expect(assigns(:versions)).to eq versions end end diff --git a/spec/features/versions_spec.rb b/spec/features/versions_spec.rb index ff73eee0..90c0fa35 100644 --- a/spec/features/versions_spec.rb +++ b/spec/features/versions_spec.rb @@ -286,8 +286,6 @@ feature 'Version' do expect(page).to have_text('Someone (probably via the console) created new commercial') visit admin_conference_program_event_path(conference.short_title, event_without_commercial) click_link 'History' - expect(event_commercial.id).not_to eq event_commercial.commercialable_id - expect(event_without_commercial.id).to eq event_commercial.id expect(page).to have_no_text('Someone (probably via the console) created new commercial') end