From 2c97fc9b42d82f9197b2db38f1bfd25ad605d2dc Mon Sep 17 00:00:00 2001 From: Rob Young Date: Wed, 13 Mar 2024 15:16:19 -0700 Subject: [PATCH] REFACTOR: Removed memoization from request specs Specs updateds: - spec/requests/stories_controller_spec.rb - spec/requests/tutorials_controller_spec.rb --- spec/requests/stories_controller_spec.rb | 55 ++++++++++------------ spec/requests/tutorials_controller_spec.rb | 3 -- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/spec/requests/stories_controller_spec.rb b/spec/requests/stories_controller_spec.rb index 0a6acd199..65baf31a4 100644 --- a/spec/requests/stories_controller_spec.rb +++ b/spec/requests/stories_controller_spec.rb @@ -1,15 +1,7 @@ # frozen_string_literal: true RSpec.describe StoriesController do - let(:story_one) { create(:story, :unread) } - let(:story_two) { create(:story, :unread) } - describe "GET /news" do - def setup - story_one - story_two - end - it "redirects to the setup page when no user exists" do get "/news" @@ -26,7 +18,7 @@ def setup it "display list of unread stories" do login_as(default_user) - setup + create(:story) get "/news" @@ -35,7 +27,7 @@ def setup it "displays the blog title and article title" do login_as(default_user) - setup + story_one = create(:story) get "/news" @@ -44,7 +36,7 @@ def setup it "displays all user actions" do login_as(default_user) - setup + create(:story) get "/news" @@ -53,7 +45,6 @@ def setup it "has correct footer links" do login_as(default_user) - setup get "/news" @@ -92,65 +83,67 @@ def setup end describe "#update" do + headers = { "CONTENT_TYPE" => "application/json" } + it "marks a story as read when it is_read not malformed" do login_as(default_user) params = { is_read: true }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :is_read).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :is_read).from(false).to(true) end it "marks a story as read when is_read is malformed" do login_as(default_user) params = { is_read: "malformed" }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :is_read).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :is_read).from(false).to(true) end it "marks a story as keep unread when it keep_unread not malformed" do login_as(default_user) params = { keep_unread: true }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :keep_unread).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :keep_unread).from(false).to(true) end it "marks a story as keep unread when keep_unread is malformed" do login_as(default_user) params = { keep_unread: "malformed" }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :keep_unread).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :keep_unread).from(false).to(true) end it "marks a story as starred when is_starred is not malformed" do login_as(default_user) params = { is_starred: true }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :is_starred).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :is_starred).from(false).to(true) end it "marks a story as starred when is_starred is malformed" do login_as(default_user) params = { is_starred: "malformed" }.to_json - headers = { "CONTENT_TYPE" => "application/json" } + story = create(:story) - expect { put("/stories/#{story_one.id}", params:, headers:) } - .to change_record(story_one, :is_starred).from(false).to(true) + expect { put("/stories/#{story.id}", params:, headers:) } + .to change_record(story, :is_starred).from(false).to(true) end end describe "#mark_all_as_read" do it "marks all unread stories as read and reload the page" do login_as(default_user) - stories = create_pair(:story, :unread) + stories = create_pair(:story) params = { story_ids: stories.map(&:id) } expect { post("/stories/mark_all_as_read", params:) } diff --git a/spec/requests/tutorials_controller_spec.rb b/spec/requests/tutorials_controller_spec.rb index 64fba0902..f5cc80b1a 100644 --- a/spec/requests/tutorials_controller_spec.rb +++ b/spec/requests/tutorials_controller_spec.rb @@ -3,9 +3,6 @@ RSpec.describe TutorialsController do describe "#index" do context "when a user has not been setup" do - let(:user) { instance_double(User) } - let(:feeds) { [instance_double(Feed), instance_double(Feed)] } - it "displays the tutorial and completes setup" do login_as(default_user)