# Write model rspec for my application

**URL:** <https://www.ruby-forum.com/t/write-model-rspec-for-my-application/260353>\
**Category:** RSpec\
**Created:** [October 11, 2020, 1:21pm UTC](https://www.ruby-forum.com/t/write-model-rspec-for-my-application/260353 "2020-10-11T13:21:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshwiniRane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@AshwiniRane](https://www.ruby-forum.com/u/AshwiniRane)\
**Post date:** [October 11, 2020, 1:21pm UTC](https://www.ruby-forum.com/t/write-model-rspec-for-my-application/260353/1 "2020-10-11T13:21:05Z")

</div>

I am a beginner in ruby and rails and struggling to write rspec code for my model methods as given below:

Please help me write rspec implementation and test examples for my methods for me to have a basic understanding of how can I proceed in this:

def get\_quarantine\_trails(event\_id)  
quarantine\_event\_result = quarantine\_events.find\_by(id: event\_id)  
quarantine\_event\_result.inventory\_items.select([:item\_number, :id])  
end

def quarantine\_events\_list  
quarantine\_events.joins(:quarantine\_trails).  
select(‘quarantine\_events.\*,count(quarantine\_trails.quarantine\_event\_id) as count\_of\_events’).  
group(‘quarantine\_events.id’)  
end

Here: quarantine\_events and quarantine\_trails are 2 models where they have direct association in between them. quarantine\_events table being my parent table and quarantine\_trails being my child table.  
inventory\_items is another model having association with quarantine\_trail table.

Help me create a rspec implementation for this 2 methods for my initial understanding.

Thank you.
