Skip to content

Commit

Permalink
Add test to check if district is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuki77 committed Apr 14, 2021
1 parent 42a9a9e commit e12dc5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/services/build_heritage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def initialize(_params, district: nil)
params = _params.to_h.deep_dup
heritage_name = params.delete(:id) || params[:name]
@heritage = Heritage.find_or_initialize_by(name: heritage_name)

# we can remove this check once we find heritage by heritage name and district name
if district && @heritage.district && district.id != @heritage.district.id
raise ExceptionHandler::InternalServerError.new("Wrong district is provided")
end

@district = district || @heritage.district
@params = convert_params_for_model params
end
Expand Down
7 changes: 7 additions & 0 deletions spec/services/build_heritage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,12 @@
end
end
end

context "when wrong district is passed" do
it "it should and throw an error" do
district = create(:district)
expect { BuildHeritage.new(params, district: district) }.to raise_error("Wrong district is provided")
end
end
end
end

0 comments on commit e12dc5e

Please sign in to comment.