Skip to content

Commit

Permalink
issue 956 - exclude orphaned stories (#971)
Browse files Browse the repository at this point in the history
* issue 956 - exclude orphaned stories from both dashboard and api controllers

* issue 956 - exclude orphaned stories from home controller for map

* issue 956 - undoing removal of orphaned stories in StoriesPage

* issue 956 - unit test

* issue 956 - unit test

* issue 956 - unit test - updating comments and variable names for clarity

* changes per comments

* Remove unused let

---------

Co-authored-by: Laura Mosher <2660801+lauramosher@users.noreply.github.com>
  • Loading branch information
ice1080 and lauramosher authored Dec 11, 2023
1 parent 8365125 commit 5cb6505
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion rails/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def create
end

helper_method def stories
policy_scope(current_community.stories)
community_stories = policy_scope(current_community.stories)
community_stories = community_stories.joins(:speakers).distinct
community_stories = community_stories.joins(:places).distinct
community_stories
end
end
1 change: 0 additions & 1 deletion rails/spec/requests/api/public_stories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@

get "/api/communities/cool_community/stories"


expect(json_meta["total"]).to eq(1)
expect(json_response["stories"].map { |s| s["id"] }).to contain_exactly(story_1.id)
end
Expand Down
42 changes: 42 additions & 0 deletions rails/spec/requests/home_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,47 @@
expect(response).to redirect_to("/users/sign_in")
end
end

context "orphaned stories" do
let(:community) { FactoryBot.create(:community, name: "Orphaned Community") }
let(:user) { FactoryBot.create(:user, community: community) }
let!(:place_1) { create(:place, community: community, region: "test place 1") }
let!(:place_2) { create(:place, community: community, region: "test place 2") }
let!(:speaker_1) { create(:speaker, community: community) }
let!(:speaker_2) { create(:speaker, community: community) }
let!(:story_1) do
create(
:story,
community: community,
places: [place_1],
speakers: [speaker_1],
desc: "This story should not be visible because it has no speaker",
permission_level: :anonymous
)
end
let!(:story_2) do
create(
:story,
community: community,
places: [place_2],
speakers: [speaker_2],
desc: "This story should not be visible because it has no place",
permission_level: :anonymous
)
end

before do
login_as user
end

it "excludes stories with no speaker and/or place" do
speaker_1.destroy
place_2.destroy
get "/home"

expect(response.body).not_to include('This story should not be visible because it has no speaker')
expect(response.body).not_to include('This story should not be visible because it has no place')
end
end
end
end

0 comments on commit 5cb6505

Please sign in to comment.