Skip to content

Commit

Permalink
needs_naming_and_not_reviewed_by_user
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Jan 29, 2024
1 parent 7800c12 commit 75c37cb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/classes/query/observation_needs_naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def parameter_declarations
# 15x faster to use AR scope to assemble the IDs vs SQL SELECT DISTINCT!
def initialize_flavor
user = User.current_id
needs_naming = Observation.needs_naming_not_reviewed_by_user(user).
needs_naming = Observation.needs_naming_and_not_reviewed_by_user(user).
map(&:id).join(", ")
where << "observations.id IN (#{needs_naming})" if needs_naming.present?

Expand Down
2 changes: 1 addition & 1 deletion app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class Observation < AbstractModel # rubocop:disable Metrics/ClassLength
where.not(id: ObservationView.where(user_id: user_id, reviewed: 1).
map(&:observation_id).uniq)
}
scope :needs_naming_not_reviewed_by_user, lambda { |user|
scope :needs_naming_and_not_reviewed_by_user, lambda { |user|
needs_naming.without_vote_by_user(user).not_reviewed_by_user(user).distinct
}
# Higher taxa: returns narrowed-down group of id'd obs,
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/observation_views_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ObservationViewsControllerTest < FunctionalTestCase
def test_update
login("mary")
obs = Observation.needs_naming_not_reviewed_by_user(users(:mary))
obs = Observation.needs_naming_and_not_reviewed_by_user(users(:mary))
obs_count = obs.count

# Have to create the o_v, none existing
Expand All @@ -17,7 +17,7 @@ def test_update
assert_redirected_to(identify_observations_path)
end

now_obs = Observation.needs_naming_not_reviewed_by_user(users(:mary))
now_obs = Observation.needs_naming_and_not_reviewed_by_user(users(:mary))
now_obs_count = now_obs.count
assert_equal(obs_count - 5, now_obs_count)
end
Expand Down
12 changes: 6 additions & 6 deletions test/controllers/observations/identify_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_identify_observations_index
login("mary")
mary = users(:mary)
# First make sure the index is showing everything.
obs = Observation.needs_naming_not_reviewed_by_user(users(:mary))
obs = Observation.needs_naming_and_not_reviewed_by_user(users(:mary))
obs_count = obs.count
mary.update(layout_count: obs_count + 1)

Expand All @@ -23,7 +23,7 @@ def test_identify_observations_index

# CLADE
# make a query, and test that the query results match obs scope
aga_obs = Observation.needs_naming_not_reviewed_by_user(mary).
aga_obs = Observation.needs_naming_and_not_reviewed_by_user(mary).
in_clade("Agaricales")
query = Query.lookup_and_save(:Observation, :needs_naming,
in_clade: "Agaricales")
Expand All @@ -35,7 +35,7 @@ def test_identify_observations_index
assert_no_flash
assert_select(".matrix-box", aga_obs.count)

bol_obs = Observation.needs_naming_not_reviewed_by_user(mary).
bol_obs = Observation.needs_naming_and_not_reviewed_by_user(mary).
in_clade("Boletus")
query = Query.lookup_and_save(:Observation, :needs_naming,
in_clade: "Boletus")
Expand All @@ -44,13 +44,13 @@ def test_identify_observations_index
# REGION
# make a query, and test that the query results match obs scope
# start with continent
sam_obs = Observation.needs_naming_not_reviewed_by_user(mary).
sam_obs = Observation.needs_naming_and_not_reviewed_by_user(mary).
in_region("South America")
query = Query.lookup_and_save(:Observation, :needs_naming,
in_region: "South America")
assert_equal(query.num_results, sam_obs.count)

cal_obs = Observation.needs_naming_not_reviewed_by_user(mary).
cal_obs = Observation.needs_naming_and_not_reviewed_by_user(mary).
in_region("California, USA")
# remember the original count, will change
cal_obs_count = cal_obs.count
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_identify_observations_index

# Vote on the first unconfident naming and check the new obs_count
# On the site, this happens via JS, so we'll do it directly
new_cal_obs = Observation.needs_naming_not_reviewed_by_user(mary).
new_cal_obs = Observation.needs_naming_and_not_reviewed_by_user(mary).
in_region("California, USA")
# Have to check for an actual naming, because some obs have no namings,
# and obs.name_id.present? doesn't necessarily mean there's a naming
Expand Down
6 changes: 3 additions & 3 deletions test/models/observation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1136,13 +1136,13 @@ def test_scope_needs_naming
observations(:peltigera_obs))
end

def test_scope_needs_naming_not_reviewed_by_user
def test_scope_needs_naming_and_not_reviewed_by_user
assert_includes(
Observation.needs_naming_not_reviewed_by_user(users(:rolf)),
Observation.needs_naming_and_not_reviewed_by_user(users(:rolf)),
observations(:fungi_obs)
)
assert_not_includes(
Observation.needs_naming_not_reviewed_by_user(users(:rolf)),
Observation.needs_naming_and_not_reviewed_by_user(users(:rolf)),
observations(:peltigera_obs)
)
end
Expand Down

0 comments on commit 75c37cb

Please sign in to comment.