erwinjunker / regressor

Generate specs for your rails application the easy way. Regressor generates model and controller specs based on validations, associations, enums, database, routes, callbacks. Use regressor to capture your rails application behaviour.
MIT License
206 stars 33 forks source link

:if and :unless conditions on ActiveRecord validations #16

Closed sha1sum closed 9 years ago

sha1sum commented 9 years ago

:if and :unless conditions on ActiveRecord validations now create "context" blocks and mock the boolean response as long as the if condition is a symbol.

Resolves #10

sha1sum commented 9 years ago

This creates something similar to the following for :unless conditions (without the comments):

  context "with conditions" do
    # given "validates :termination_date, presence: true, unless: :third_party?"
    before do
      allow(subject).to receive(:third_party?).and_return(false)
    end

    it { is_expected.to validate_presence_of :termination_date }
  end

... and the following for :if conditions:

  context "with conditions" do
    # given "validates :manager_id, presence: true, if: :third_party?"
    before do
      allow(subject).to receive(:third_party?).and_return(true)
    end

    it { is_expected.to validate_presence_of :manager_id }
  end
erwinjunker commented 9 years ago

Awesome! I will merge this pull request and ad it to the next version 0.5.9 for rubygems which i plan to release next week. I will play with this a little bit today.

Thanks :)