Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.

Commit

Permalink
Add spec to family_request.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
EmersonAraki committed Sep 16, 2019
1 parent 83fec1c commit bb724cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/family_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class FamilyRequest < ApplicationRecord
has_many :family_request_children, dependent: :destroy
has_many :children, through: :family_request_children

validates :partner, presence: true

def export_json
items_count_map = children.each_with_object({}) do |child, map|
map[child.item_needed_diaperid] ||= 0
Expand Down
19 changes: 19 additions & 0 deletions spec/models/family_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,23 @@
require "rails_helper"

RSpec.describe FamilyRequest, type: :model do
it { is_expected.to validate_presence_of(:partner) }

it { should have_many(:family_request_children).dependent(:destroy) }

it { should have_many(:children).through(:family_request_children) }

describe "#export_json" do
let(:partner) { create(:partner) }
let(:family_request) { create(:family_request, partner: partner) }
it "should return a JSON format" do
result = {
organization_id: partner.id,
partner_id: partner.id,
requested_items: []
}.to_json

expect(family_request.export_json).to eql result
end
end
end

0 comments on commit bb724cb

Please sign in to comment.