-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4142 from elasticspoon/4135-request-value-preserv…
…ation 4135 Individuals Requests Preserve Values
- Loading branch information
Showing
6 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Partners::FamilyRequest do | ||
describe "Partners::FamilyRequest.new_with_attrs" do | ||
it "creates a new FamilyRequest with attributes" do | ||
attributes = [{item_id: 1, person_count: 3}] | ||
request = Partners::FamilyRequest.new_with_attrs(attributes) | ||
|
||
expect(request.items.length).to eq(1) | ||
expect(request.items.first.item_id).to eq(1) | ||
expect(request.items.first.person_count).to eq(3) | ||
end | ||
end | ||
|
||
describe "#items_attributes=" do | ||
let(:item_attributes) { {"0" => {item_id: 1, person_count: 2}, "1" => {item_id: 2, person_count: 3}} } | ||
let(:family_request) { Partners::FamilyRequest.new({}) } | ||
|
||
it "assigns items based on given attributes" do | ||
family_request.items_attributes = item_attributes | ||
expect(family_request.items.length).to eq(2) | ||
expect(family_request.items.first.item_id).to eq(1) | ||
expect(family_request.items.first.person_count).to eq(2) | ||
expect(family_request.items.last.item_id).to eq(2) | ||
expect(family_request.items.last.person_count).to eq(3) | ||
end | ||
|
||
it "creates instances of Item with correct attributes" do | ||
family_request.items_attributes = item_attributes | ||
expect(family_request.items.first).to be_an_instance_of(Partners::FamilyRequest::Item) | ||
expect(family_request.items.last).to be_an_instance_of(Partners::FamilyRequest::Item) | ||
end | ||
|
||
it "overrides existing items" do | ||
family_request = Partners::FamilyRequest.new({}, initial_items: 6) | ||
expect(family_request.items.length).to eq(6) | ||
|
||
family_request.items_attributes = item_attributes | ||
expect(family_request.items.length).to eq(2) | ||
expect(family_request.items.first.item_id).to eq(1) | ||
expect(family_request.items.first.person_count).to eq(2) | ||
expect(family_request.items.last.item_id).to eq(2) | ||
expect(family_request.items.last.person_count).to eq(3) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters