-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor matches routes to Rails convention * Refactor MatchesController to use Rails naming conventions such as destroy instead of delete * Move some business logic from MatchesController into AdopterApplication model * Add tests for new withdrawing and retiring application methods * Add safe navigation in case a match is created where no paired AdopterApplication exists * Adjust strong params to require match * Fix params reference in get_pet_id
- Loading branch information
Showing
8 changed files
with
129 additions
and
37 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
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,48 @@ | ||
require "test_helper" | ||
|
||
class AdopterApplicationTest < ActiveSupport::TestCase | ||
setup do | ||
@application = create(:adopter_application) | ||
end | ||
|
||
context "self.retire_applications" do | ||
context "when some applications match pet_id and some do not" do | ||
setup do | ||
@selected_applications = Array.new(3) { | ||
create(:adopter_application, pet_id: @application.pet_id) | ||
} | ||
@unselected_applications = Array.new(2) { | ||
create(:adopter_application) | ||
} | ||
end | ||
|
||
should "update status of matching applications to :adoption_made" do | ||
AdopterApplication.retire_applications(pet_id: @application.pet_id) | ||
|
||
@selected_applications.each do |application| | ||
assert_equal "adoption_made", application.reload.status | ||
end | ||
end | ||
|
||
should "not update status of mismatching applications" do | ||
cached_statuses = @unselected_applications.map(&:status) | ||
|
||
AdopterApplication.retire_applications(pet_id: @application.pet_id) | ||
|
||
current_statuses = @unselected_applications.map do |application| | ||
application.reload.status | ||
end | ||
|
||
assert_equal cached_statuses, current_statuses | ||
end | ||
end | ||
end | ||
|
||
context "#withdraw" do | ||
should "update status to :withdrawn" do | ||
@application.withdraw | ||
|
||
assert "withdrawn", @application.status | ||
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