Files
nairobi/spec/models/milestone_spec.rb
Javi Martín 66334b5757 Add globalizable tests for all translatable models
So now we test in depth at the model level, and can be a bit more
relaxed about integration tests for translations.

Note we're defining some extra factories to make sure all translatable
attributes with presence validation rules are mandatory. This way we can
simplify the way we obtain required fields, using `required_attribute?`.
Otherwise, fields having an `unless` condition in their presence
validation rules would count as mandatory even when they're not.
2019-09-23 18:01:44 +02:00

59 lines
1.7 KiB
Ruby

require "rails_helper"
describe Milestone do
it_behaves_like "globalizable", :milestone_with_description
describe "Validations" do
let(:milestone) { build(:milestone) }
it "is valid" do
expect(milestone).to be_valid
end
it "is valid without a title" do
milestone.title = nil
expect(milestone).to be_valid
end
it "is not valid without a description if status is empty" do
milestone.status = nil
milestone.description = nil
expect(milestone).not_to be_valid
end
it "is valid without a description if status is present" do
milestone.description = nil
expect(milestone).to be_valid
end
it "is not valid without a milestoneable" do
milestone.milestoneable_id = nil
expect(milestone).not_to be_valid
end
it "is not valid if description and status are not present" do
milestone.description = nil
milestone.status_id = nil
expect(milestone).not_to be_valid
end
it "is valid without status if description is present" do
milestone.status_id = nil
expect(milestone).to be_valid
end
end
describe ".published" do
it "uses the application's time zone date", :with_different_time_zone do
published_in_local_time_zone = create(:milestone,
publication_date: Date.today)
published_in_application_time_zone = create(:milestone,
publication_date: Date.current)
expect(Milestone.published).to include(published_in_application_time_zone)
expect(Milestone.published).not_to include(published_in_local_time_zone)
end
end
end