Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4640

how to change subject for shoulda matchers

$
0
0

I'm having trouble with the following attributes within my class. I have a date attribute with presence true that is enforced at database level too:

validates :date, presence: true

In addition to that, I need to enforce combined uniqueness for the following two attributes

validates :name, uniqueness: { scope: :parent_id }

So far... everything is ok, but I want to have a spec testing the uniqueness

it { should validate_uniqueness_of(:name).scoped_to(:parent_id) }

But the problem with line above is that it will try to insert a record on db by just using a random name and parent_id values letting the date one to be nil. Thus, it fails on database.

I already tried doing subject { build(:my_model) } on the test, however the it line is still creating it's own one and not setting the date attribute.

How can I make shoulda to use the subject I created? I am missing something?


Viewing all articles
Browse latest Browse all 4640

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>