diff --git a/app/models/space.rb b/app/models/space.rb index 3dd16a5a..db41f7ef 100644 --- a/app/models/space.rb +++ b/app/models/space.rb @@ -178,9 +178,9 @@ def relevant_space_facilities(grouped: false) group_space_facilities(relevant) end - # Facilities (not space facilities :P) that are relevant. + # Facilities (found through space facilities) that are relevant. def relevant_facilities - space_facilities.where(relevant: true).map(&:facility) + space_facilities.includes(:facility).where(relevant: true).map(&:facility) end # Space Facilities that are typically NOT relevant for the space diff --git a/config/locales/nb.yml b/config/locales/nb.yml index a9621286..1c99986a 100644 --- a/config/locales/nb.yml +++ b/config/locales/nb.yml @@ -21,11 +21,6 @@ nb: delete_confirmation: "Er du sikker på at du vil slette?" close_contact: "Lukk" tooltips: - facility_single_experience: - was_allowed: 'Fikk bruke' - was_not_allowed: 'Fikk ikke bruke' - was_not_available: 'De har ikke' - havent_asked: 'Ikke spurt' facility_aggregated_experience: unknown: 'Usikkert. Ingen har spurt!' impossible: 'De har ikke.' diff --git a/spec/fabricators/facilities_category_fabricator.rb b/spec/fabricators/facilities_category_fabricator.rb new file mode 100644 index 00000000..e88a3a94 --- /dev/null +++ b/spec/fabricators/facilities_category_fabricator.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +Fabricator(:facilities_category) do + facility + facility_category +end + +# == Schema Information +# +# Table name: facilities_categories +# +# id :bigint not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# facility_category_id :bigint not null +# facility_id :bigint not null +# +# Indexes +# +# index_facilities_categories_on_facility_category_id (facility_category_id) +# index_facilities_categories_on_facility_id (facility_id) +# +# Foreign Keys +# +# fk_rails_... (facility_category_id => facility_categories.id) +# fk_rails_... (facility_id => facilities.id) +# diff --git a/spec/fabricators/facility_fabricator.rb b/spec/fabricators/facility_fabricator.rb index dd606151..19ec9ead 100644 --- a/spec/fabricators/facility_fabricator.rb +++ b/spec/fabricators/facility_fabricator.rb @@ -3,6 +3,10 @@ Fabricator(:facility) do title { Faker::Name.first_name } icon { Faker::Name.first_name } + + after_create do |facility| + Fabricate(:facilities_category, facility:) + end end # == Schema Information diff --git a/spec/fabricators/image_fabricator.rb b/spec/fabricators/image_fabricator.rb index 267dba2f..5377f206 100644 --- a/spec/fabricators/image_fabricator.rb +++ b/spec/fabricators/image_fabricator.rb @@ -4,3 +4,19 @@ space image { Rack::Test::UploadedFile.new(TestImageHelper.image_path, TestImageHelper.content_type) } end + +# == Schema Information +# +# Table name: images +# +# id :bigint not null, primary key +# caption :string +# credits :string +# created_at :datetime not null +# updated_at :datetime not null +# space_id :bigint +# +# Indexes +# +# index_images_on_space_id (space_id) +# diff --git a/spec/fabricators/space_fabricator.rb b/spec/fabricators/space_fabricator.rb index 1949a4cc..20d8233d 100644 --- a/spec/fabricators/space_fabricator.rb +++ b/spec/fabricators/space_fabricator.rb @@ -10,6 +10,37 @@ space_group space_types { [Fabricate(:space_type)] } star_rating { nil } + + after_create do |space| + space_type = space.space_types.first + + relevant_facility_one = Fabricate(:facility) + relevant_facility_two = Fabricate(:facility) + + # Make them relevant: + Fabricate(:space_types_facility, + space_type:, + facility: relevant_facility_one) + Fabricate(:space_types_facility, + space_type:, + facility: relevant_facility_two) + + # Then create two relevant space facilities: + Fabricate(:space_facility, + space:, + facility: relevant_facility_one) + Fabricate(:space_facility, + space:, + facility: relevant_facility_two) + + # And four irrelevant ones: + Fabricate.times(4, + :space_facility, + space:) + + # Then aggregate reviews + space.aggregate_facility_reviews + end end # == Schema Information diff --git a/spec/fabricators/space_facility_fabricator.rb b/spec/fabricators/space_facility_fabricator.rb new file mode 100644 index 00000000..4cfe2d77 --- /dev/null +++ b/spec/fabricators/space_facility_fabricator.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +Fabricator(:space_facility) do + facility + relevant true + experience :unknown +end + +# == Schema Information +# +# Table name: space_facilities +# +# id :bigint not null, primary key +# description :string +# experience :integer +# relevant :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# facility_id :bigint not null +# space_id :bigint not null +# +# Indexes +# +# index_space_facilities_on_facility_id (facility_id) +# index_space_facilities_on_space_id (space_id) +# +# Foreign Keys +# +# fk_rails_... (facility_id => facilities.id) +# fk_rails_... (space_id => spaces.id) +# diff --git a/spec/fabricators/space_types_facility_fabricator.rb b/spec/fabricators/space_types_facility_fabricator.rb new file mode 100644 index 00000000..78af5ef6 --- /dev/null +++ b/spec/fabricators/space_types_facility_fabricator.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +Fabricator(:space_types_facility) do + space_type + facility +end + +# == Schema Information +# +# Table name: space_types_facilities +# +# id :bigint not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# facility_id :bigint not null +# space_type_id :bigint not null +# +# Indexes +# +# index_space_types_facilities_on_facility_id (facility_id) +# index_space_types_facilities_on_space_type_id (space_type_id) +# +# Foreign Keys +# +# fk_rails_... (facility_id => facilities.id) +# fk_rails_... (space_type_id => space_types.id) +# diff --git a/spec/features/user_creates_facility_reviews_spec.rb b/spec/features/user_creates_facility_reviews_spec.rb new file mode 100644 index 00000000..506d1d62 --- /dev/null +++ b/spec/features/user_creates_facility_reviews_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "User creates facility reviews", :js do + let!(:space) do + Fabricate(:space, address: "Ulefossvegen 32", post_number: 3730, post_address: "Skien", lat: 59.196, lng: 9.603) + end + + before do + create_user! + end + + it "User leaves facility reviews for both facilities" do + no_reviews_selector = "li[title='#{I18n.t('tooltips.facility_aggregated_experience.unknown')}']" + reviewed_selector = "li[title='#{I18n.t('tooltips.facility_aggregated_experience.likely')}']" + + first_facility = space.space_facilities.first.facility + second_facility = space.space_facilities.second.facility + + login_and_logout_with_warden do + visit space_path(space) + + expect(page).to have_selector(no_reviews_selector) + + find("button[aria-label='Rediger fasiliteter']").click + + fieldset = find("fieldset", text: first_facility.title) + within(fieldset) do + click_on("Rediger") + choose(I18n.t("reviews.form.facility_experience_particular_tense.was_allowed"), allow_label_click: true) + end + + second_fieldset = find("fieldset", text: second_facility.title) + within(second_fieldset) do + click_on("Rediger") + choose(I18n.t("reviews.form.facility_experience_particular_tense.was_allowed"), allow_label_click: true) + end + + click_on(I18n.t("facility_reviews.save")) + + expect(page).to have_selector(reviewed_selector) + expect(page).to have_no_selector(no_reviews_selector) + end + end +end diff --git a/spec/features/user_views_homepage_spec.rb b/spec/features/user_views_homepage_spec.rb index 711ecfa1..59eecdb2 100644 --- a/spec/features/user_views_homepage_spec.rb +++ b/spec/features/user_views_homepage_spec.rb @@ -18,10 +18,6 @@ create_user! login_with_warden! - category = Fabricate(:facility_category) - category.facilities << facility_toilet - category.facilities << facility_beds - Fabricate(:facility_review, space: space_one, facility: facility_toilet, experience: :was_allowed) Fabricate(:facility_review, space: space_one, facility: facility_beds, experience: :was_not_allowed)