-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike of community resource browsing #980
Changes from 11 commits
ff8e64f
2bb2807
0ffc4c9
32a9929
271ea0f
f888f85
9c7f9ae
ac44084
dc7c4e8
fa6003b
3806c3f
cd5aa11
37a2ede
aea2cad
7ce2020
5270467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,17 @@ class CommunityResource < ApplicationRecord | |
|
||
validates :name, :description, :publish_from, presence: true | ||
|
||
# We're not sure if we need or want these validations. Adding them now assuming it will be easier to remove them later than the other way around | ||
validates :service_areas, presence: true | ||
validates_associated :service_areas | ||
validates :tag_list, presence: true | ||
|
||
accepts_nested_attributes_for :organization | ||
|
||
scope :approved, -> { where(is_approved: true) } | ||
scope :pending_review, -> { where(is_approved: false) } | ||
# TODO: add tests for this? | ||
scope :in_service_areas, ->(ids) { joins(:service_areas).where(service_areas: {id: ids}).distinct } | ||
|
||
def self.published | ||
before_now = DateTime.new..Time.current | ||
|
@@ -31,20 +38,48 @@ def self.published | |
) | ||
end | ||
|
||
def title; description; end | ||
def self.matchable; published; end | ||
|
||
def published? | ||
now = Time.current | ||
is_approved && | ||
(publish_from.present? ? publish_from <= now : true) && | ||
(publish_until.nil? || now < publish_until) | ||
end | ||
|
||
def categories_for_tags | ||
Category.where(name: tag_list) | ||
h-m-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def all_tags_unique | ||
all_tags_list.flatten.map(&:downcase).uniq | ||
end | ||
|
||
def all_tags_to_s | ||
all_tags_unique.join(', ') | ||
end | ||
|
||
def preferred_contact_method | ||
# TODO: This is a hack that makes things work for now | ||
# The test creates a contact method that will match this | ||
# and the dev db seeding creates a couple, too | ||
ContactMethod.method_name('call').last | ||
Comment on lines
+64
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some way I can fix this in its own PR? In other codebases I work in, this whole workflow is something I'd hide behind a feature flag so I can get this PR out first, and then get the contact methods for community resources working in a separate PR. I could also try to fix it here, especially if anyone's willing to help me with it. Please let me know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an issue for this at #986 |
||
end | ||
|
||
def type | ||
"Community Resource" | ||
end | ||
|
||
def inexhaustible | ||
true | ||
end | ||
|
||
def urgency_level_id | ||
UrgencyLevel::TYPES.last.id | ||
end | ||
Comment on lines
+70
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @exbinary mentioned that these don't feel like actual attributes, behaviors, or properties of a community resource, and so they might be better off in an abstraction or interface class that turns community resources into something blueprint-able |
||
|
||
def person; end | ||
end | ||
|
||
# == Schema Information | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ | |
'name' => contribution.person.preferred_contact_method.name | ||
} | ||
}, | ||
'service_area' => { | ||
'service_areas' => [{ | ||
'description' => contribution.service_area.description, | ||
'id' => contribution.service_area.id, | ||
'name' => expected_area_name, | ||
|
@@ -58,7 +58,7 @@ | |
'street_address' => contribution.service_area.location.street_address, | ||
'zip' => contribution.service_area.location.zip | ||
} | ||
}, | ||
}], | ||
# "map_location" => "44.5,-85.1", | ||
'title' => contribution.title, | ||
'description' => contribution.description, | ||
|
@@ -73,4 +73,29 @@ | |
result = ContributionBlueprint.render(contribution, show_view_path: true, current_user: user) | ||
expect(JSON.parse(result)['view_path']).to eq(expected_path) | ||
end | ||
|
||
it 'can serialize a community resource as a contribution' do | ||
resource = create(:community_resource) | ||
# The test database defaults to having no contact methods, so we need at least one | ||
default_contact_method = create(:contact_method) | ||
expected_result = { | ||
"id" => resource.id, | ||
"category_tags" => [], | ||
"contact_types" => [{"id" => default_contact_method.id, "name" => "Call"}], | ||
"contribution_type" => "Community Resource", | ||
"created_at" => resource.created_at.to_f * 1000, | ||
"description" => "Food for the revolution", | ||
"inexhaustible" => true, | ||
"location" => nil, | ||
"match_path" => nil, | ||
"name" => "Free breakfast for School Children Program", | ||
"person" => nil, | ||
Comment on lines
+90
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @exbinary pointed out how hashes like this to test blobs of JSON are fragile since small changes can then require lots of edits |
||
"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) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.