Browse Source

Push fixes #7

pull/264/head
Stéphane Meny 3 years ago
parent
commit
7210915901
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 518
      spec/models/case_log_spec.rb
  2. 38
      spec/models/validations/property_validations_spec.rb
  3. 4
      spec/presenters/error_summary_full_messages_presenter_spec.rb
  4. 2
      spec/requests/auth/passwords_controller_spec.rb

518
spec/models/case_log_spec.rb

File diff suppressed because it is too large Load Diff

38
spec/models/validations/property_validations_spec.rb

@ -1,59 +1,39 @@
require "rails_helper" require "rails_helper"
require_relative "../../request_helper" require_relative "../../request_helper"
RSpec.describe CaseLog do
let(:owning_organisation) { FactoryBot.create(:organisation) }
let(:managing_organisation) { owning_organisation }
before do
RequestHelper.stub_http_requests
end
describe "#new" do
it "raises an error when offered is present and invalid" do
expect {
described_class.create!(
offered: "random",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
RSpec.describe Validations::PropertyValidations do RSpec.describe Validations::PropertyValidations do
let(:subject) { subject_class.new } subject(:property_validator) { property_validator_class.new }
let(:subject_class) { Class.new { include Validations::PropertyValidations } }
let(:property_validator_class) { Class.new { include Validations::PropertyValidations } }
let(:record) { FactoryBot.create(:case_log) } let(:record) { FactoryBot.create(:case_log) }
let(:expected_error) { I18n.t("validations.property.offered.relet_number") } let(:expected_error) { I18n.t("validations.property.offered.relet_number") }
describe "#validate_property_number_of_times_relet" do describe "#validate_property_number_of_times_relet" do
it "does not add an error if the record offered is missing" do it "does not add an error if the record offered is missing" do
record.offered = nil record.offered = nil
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does not add an error if offered is valid (number between 0 and 20)" do it "does not add an error if offered is valid (number between 0 and 20)" do
record.offered = 0 record.offered = 0
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
record.offered = 10 record.offered = 10
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
record.offered = 20 record.offered = 20
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does add an error when offered is invalid" do it "does add an error when offered is invalid" do
record.offered = "invalid" record.offered = "invalid"
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).not_to be_empty expect(record.errors).not_to be_empty
expect(record.errors["offered"]).to include(match(expected_error)) expect(record.errors["offered"]).to include(match(expected_error))
record.offered = 21 record.offered = 21
subject.validate_property_number_of_times_relet(record) property_validator.validate_property_number_of_times_relet(record)
expect(record.errors).not_to be_empty expect(record.errors).not_to be_empty
expect(record.errors["offered"]).to include(match(expected_error)) expect(record.errors["offered"]).to include(match(expected_error))
end end

4
spec/presenters/error_summary_full_messages_presenter_spec.rb

@ -1,12 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe ErrorSummaryFullMessagesPresenter do RSpec.describe ErrorSummaryFullMessagesPresenter do
subject { described_class.new(error_messages) } subject(:error_summary_presenter) { described_class.new(error_messages) }
let(:error_messages) { { reset_password_token: %w[expired] } } let(:error_messages) { { reset_password_token: %w[expired] } }
let(:formatted_error_messages) { [[:reset_password_token, "Reset password token expired"]] } let(:formatted_error_messages) { [[:reset_password_token, "Reset password token expired"]] }
it "formats messages to include the attribute name" do it "formats messages to include the attribute name" do
expect(subject.formatted_error_messages).to eq(formatted_error_messages) expect(error_summary_presenter.formatted_error_messages).to eq(formatted_error_messages)
end end
end end

2
spec/requests/auth/passwords_controller_spec.rb

@ -4,7 +4,7 @@ require_relative "../../support/devise"
RSpec.describe Auth::PasswordsController, type: :request do RSpec.describe Auth::PasswordsController, type: :request do
let(:params) { { user: { email: email } } } let(:params) { { user: { email: email } } }
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:notify_client) { double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }
before do before do
allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client)

Loading…
Cancel
Save