2019-04-28 21:10:54 +03:00
|
|
|
require "rails_helper"
|
2014-08-10 19:57:46 +03:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
RSpec.describe Conference, type: :model do
|
|
|
|
describe "title" do
|
|
|
|
it "must not be blank" do
|
|
|
|
expect(build(:conference, title: "")).to have_error_on :title
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "must be unique" do
|
|
|
|
create :conference, title: "ExampleConf"
|
|
|
|
expect(build(:conference, title: "ExampleConf")).to have_error_on :title
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
2014-11-04 21:16:06 +02:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "must be translatable" do
|
2014-11-04 21:16:06 +02:00
|
|
|
conference = build(:conference)
|
|
|
|
expect(conference).to have_translatable :title
|
|
|
|
end
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "email" do
|
|
|
|
it "must be present" do
|
|
|
|
expect(build(:conference, email: "")).to have_error_on :email
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "can contain exatly one @" do
|
|
|
|
expect(build(:conference, email: "test@@example.com")).to have_error_on :email
|
|
|
|
expect(build(:conference, email: "test@example.com")).to_not have_error_on :email
|
|
|
|
expect(build(:conference, email: "testexample.com")).to have_error_on :email
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "description" do
|
|
|
|
it "must be present" do
|
|
|
|
expect(build(:conference, description: "")).to have_error_on :description
|
2014-11-04 21:16:06 +02:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "must be translatable" do
|
2014-11-04 21:16:06 +02:00
|
|
|
expect(build(:conference)).to have_translatable :description
|
|
|
|
end
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "is invalid without a start date" do
|
2014-08-10 19:57:46 +03:00
|
|
|
expect(build(:conference, start_date: nil)).to have_error_on :start_date
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "is invalid without an end date" do
|
2014-08-10 19:57:46 +03:00
|
|
|
expect(build(:conference, end_date: nil)).to have_error_on :end_date
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "is invalid when the end date is before the start date" do
|
|
|
|
expect(build(:conference, start_date: "2014-07-29 21:29:13", end_date: "2014-07-28 01:00:00")).to have_error_on :end_date
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|
2014-11-04 23:02:28 +02:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "tracks association" do
|
2014-11-04 23:02:28 +02:00
|
|
|
let(:conference) { build :conference }
|
|
|
|
let(:track) { build :track }
|
|
|
|
|
|
|
|
before do
|
|
|
|
conference.save
|
|
|
|
track.conference = conference
|
|
|
|
track.save
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "links the conference to its tracks" do
|
2014-11-04 23:02:28 +02:00
|
|
|
expect(conference.tracks).to include track
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "halls association" do
|
2014-11-04 23:02:28 +02:00
|
|
|
let(:conference) { build :conference }
|
|
|
|
let(:hall) { build :hall }
|
|
|
|
|
|
|
|
before do
|
|
|
|
conference.save
|
|
|
|
hall.conference = conference
|
|
|
|
hall.save
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "has many associated halls" do
|
2014-11-04 23:02:28 +02:00
|
|
|
expect(conference.halls).to include hall
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "call for participation association" do
|
2015-04-20 18:55:06 +03:00
|
|
|
let(:conference) { build :conference }
|
|
|
|
let(:call_for_participation) { build :call_for_participation }
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
conference.save
|
|
|
|
call_for_participation.conference = conference
|
|
|
|
call_for_participation.save
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "has one call for participation" do
|
2015-04-20 18:55:06 +03:00
|
|
|
expect(conference.call_for_participation).to eq call_for_participation
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "destroys the associated call for participation when destroyed" do
|
2015-04-20 18:55:06 +03:00
|
|
|
conference.destroy
|
|
|
|
expect { CallForParticipation.find(call_for_participation.id) }.to raise_exception ActiveRecord::RecordNotFound
|
|
|
|
end
|
2015-05-23 18:47:08 +03:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "creates an associated call for participation when the conference is created" do
|
2015-05-23 18:47:08 +03:00
|
|
|
conference.save
|
|
|
|
expect(conference.call_for_participation).to be_present
|
|
|
|
end
|
2015-04-20 18:55:06 +03:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "accepts nested attributes for tracks" do
|
2014-11-04 23:02:28 +02:00
|
|
|
track_attributes = build(:track, conference: nil).attributes
|
|
|
|
conference = create :conference
|
|
|
|
expect { conference.update tracks_attributes: [track_attributes]}.to change { conference.tracks.count }.by 1
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "rejects nested attributes for tracks when they are all blank" do
|
2014-11-04 23:02:28 +02:00
|
|
|
conference = create :conference
|
2019-04-28 21:10:54 +03:00
|
|
|
expect { conference.update tracks_attributes: [{"name" => "", "description" => ""}]}.to_not change { conference.tracks.count }
|
2014-11-04 23:02:28 +02:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "allows destruction of tracks by nested attributes" do
|
2014-11-04 23:02:28 +02:00
|
|
|
conference = create :conference
|
|
|
|
track_attributes = create(:track, conference: conference).attributes
|
2019-04-28 21:10:54 +03:00
|
|
|
track_attributes["_destroy"] = 1
|
2014-11-04 23:02:28 +02:00
|
|
|
expect { conference.update tracks_attributes: [track_attributes]}.to change { conference.tracks.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "accepts nested attributes for halls" do
|
2014-11-04 23:02:28 +02:00
|
|
|
hall_attributes = build(:hall, conference: nil).attributes
|
|
|
|
conference = create :conference
|
|
|
|
expect { conference.update halls_attributes: [hall_attributes]}.to change { conference.halls.count }.by 1
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "rejects nested attributes for halls when they are all blank" do
|
2014-11-04 23:02:28 +02:00
|
|
|
conference = create :conference
|
2019-04-28 21:10:54 +03:00
|
|
|
expect { conference.update halls_attributes: [{"name" => "", "description" => ""}]}.to_not change { conference.halls.count }
|
2014-11-04 23:02:28 +02:00
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "allows destruction of halls by nested attributes" do
|
2014-11-04 23:02:28 +02:00
|
|
|
conference = create :conference
|
|
|
|
hall_attributes = create(:hall, conference: conference).attributes
|
2019-04-28 21:10:54 +03:00
|
|
|
hall_attributes["_destroy"] = 1
|
2014-11-04 23:02:28 +02:00
|
|
|
expect { conference.update halls_attributes: [hall_attributes]}.to change { conference.halls.count }.by(-1)
|
|
|
|
end
|
2014-08-10 19:57:46 +03:00
|
|
|
end
|