Skip to content

Commit

Permalink
Merge pull request #578 from alphagov/move-email-validations-to-on-cr…
Browse files Browse the repository at this point in the history
…eate

Only validate emails on create
  • Loading branch information
pixeltrix authored May 1, 2017
2 parents 5e2ed64 + 33401e1 commit fcbcc8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/staged/validations/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Email
extend ActiveSupport::Concern

included do
validates :email, presence: true, email: { allow_blank: true }
validates :email, presence: true, email: { allow_blank: true }, on: :create
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/staged/validations/multiple_signers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module MultipleSigners
extend ActiveSupport::Concern

included do
validate do |signature|
validate on: :create do |signature|
matcher = ::Signature.where(:email => signature.email, :petition_id => signature.petition_id)
matcher = matcher.where("signatures.id != ?", signature.id) unless signature.new_record?
existing_email_address_count = matcher.count
Expand Down
25 changes: 25 additions & 0 deletions spec/models/petition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,31 @@
end
end
end

context "when the creator's signature is now invalid" do
let(:creator) { petition.creator_signature }

before do
creator.update_column(:email, "[email protected]")
creator.reload
end

it "sets the state to STOPPED" do
expect {
petition.stop!(dissolution_at)
}.to change {
petition.state
}.from(Petition::PENDING_STATE).to(Petition::STOPPED_STATE)
end

it "sets the stopped date to the dissolution time" do
expect {
petition.stop!(dissolution_at)
}.to change {
petition.stopped_at
}.from(nil).to(dissolution_at)
end
end
end

describe '#flag' do
Expand Down

0 comments on commit fcbcc8a

Please sign in to comment.