Skip to content

Commit

Permalink
REFACTOR: Removed memoization from request specs
Browse files Browse the repository at this point in the history
Specs updateds:
- spec/requests/stories_controller_spec.rb
- spec/requests/tutorials_controller_spec.rb
  • Loading branch information
rhyoung214 committed Mar 13, 2024
1 parent 4ebbaab commit 2c97fc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
55 changes: 24 additions & 31 deletions spec/requests/stories_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -26,7 +18,7 @@ def setup

it "display list of unread stories" do
login_as(default_user)
setup
create(:story)

get "/news"

Expand All @@ -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"

Expand All @@ -44,7 +36,7 @@ def setup

it "displays all user actions" do
login_as(default_user)
setup
create(:story)

get "/news"

Expand All @@ -53,7 +45,6 @@ def setup

it "has correct footer links" do
login_as(default_user)
setup

get "/news"

Expand Down Expand Up @@ -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:) }
Expand Down
3 changes: 0 additions & 3 deletions spec/requests/tutorials_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2c97fc9

Please sign in to comment.