Skip to content

Commit

Permalink
fix tests that fail due to new community resource validations
Browse files Browse the repository at this point in the history
also destroy relevant join table records when destroying a community resource
  • Loading branch information
Howard M. Miller committed Sep 18, 2021
1 parent 3806c3f commit cd5aa11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/community_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CommunityResource < ApplicationRecord

has_many :matches_as_receiver
has_many :matches_as_provider
has_many :community_resource_service_areas
has_many :community_resource_service_areas, dependent: :destroy
has_many :service_areas, through: :community_resource_service_areas

validates :name, :description, :publish_from, presence: true
Expand Down
14 changes: 8 additions & 6 deletions spec/blueprints/contribution_blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
end

it 'can serialize a community resource as a contribution' do
resource = create(:community_resource)
resource = create(:community_resource, tag_list: expected_category)
# The test database defaults to having no contact methods, so we need at least one
default_contact_method = create(:contact_method)
expected_result = {
expected_result_without_service_area = {
"id" => resource.id,
"category_tags" => [],
"category_tags" => [{"id" => expected_category_id, "name" => expected_category}],
"contact_types" => [{"id" => default_contact_method.id, "name" => "Call"}],
"contribution_type" => "Community Resource",
"created_at" => resource.created_at.to_f * 1000,
Expand All @@ -90,12 +90,14 @@
"match_path" => nil,
"name" => "Free breakfast for School Children Program",
"person" => nil,
"service_areas" => [],
"title" => "Food for the revolution",
"urgency" => {"id" => 4, "name" => "Anytime"},
"view_path" => nil
}
result = ContributionBlueprint.render(resource, current_user: user)
expect(JSON.parse(result)).to eq(expected_result)
result = JSON.parse(ContributionBlueprint.render(resource, current_user: user))
result_without_service_areas = result.dup
result_without_service_areas.delete("service_areas")
expect(result_without_service_areas).to eq(expected_result_without_service_area)
expect(result["service_areas"].first["id"]).to eq(resource.service_areas.first.id)
end
end
6 changes: 5 additions & 1 deletion spec/forms/community_resource_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

RSpec.describe CommunityResourceForm do
let!(:location_type) { create :location_type }
let!(:service_area) { create :service_area }
let(:category) { create :category }
let(:params) do
{
name: 'Free breakfast program',
Expand All @@ -13,7 +15,9 @@
},
organization_attributes: {
name: 'Black Panther Party'
}
},
service_area_ids: [service_area.id],
tag_list: [category.name]
}
end

Expand Down
7 changes: 6 additions & 1 deletion spec/requests/community_resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

RSpec.describe '/community_resources', type: :request do
let!(:location_type) { create :location_type }
let!(:service_area) { create :service_area }
let(:community_resource) { create :community_resource }
let(:category) { create :category }

let(:params) do
# binding.pry
{community_resource: {
:name => 'Free Breakfast Program',
:description => 'Food for the rev!',
Expand All @@ -18,7 +21,9 @@
state: 'NY',
zip: '11754',
location_type: location_type.id
}
},
:service_area_ids => [service_area.id],
:tag_list => [category.name]
}}
end

Expand Down

0 comments on commit cd5aa11

Please sign in to comment.