Skip to content

Commit bda1388

Browse files
authored
Replace removed update_attributes method (#614)
This will replace the method `update_attributes` that was removed in ActiveRecord 6.1. Fixes #612 Refactored tests to not mock out method calls
1 parent 223f756 commit bda1388

File tree

8 files changed

+24
-32
lines changed

8 files changed

+24
-32
lines changed

app/commands/stories/mark_as_read.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
require_relative "../../repositories/story_repository"
22

33
class MarkAsRead
4-
def initialize(story_id, repository = StoryRepository)
4+
def initialize(story_id)
55
@story_id = story_id
6-
@repo = repository
76
end
87

98
def mark_as_read
10-
@repo.fetch(@story_id).update_attributes(is_read: true)
9+
StoryRepository.fetch(@story_id).update!(is_read: true)
1110
end
1211
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
require_relative "../../repositories/story_repository"
22

33
class MarkAsStarred
4-
def initialize(story_id, repository = StoryRepository)
4+
def initialize(story_id)
55
@story_id = story_id
6-
@repo = repository
76
end
87

98
def mark_as_starred
10-
@repo.fetch(@story_id).update_attributes(is_starred: true)
9+
StoryRepository.fetch(@story_id).update!(is_starred: true)
1110
end
1211
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
require_relative "../../repositories/story_repository"
22

33
class MarkAsUnread
4-
def initialize(story_id, repository = StoryRepository)
4+
def initialize(story_id)
55
@story_id = story_id
6-
@repo = repository
76
end
87

98
def mark_as_unread
10-
@repo.fetch(@story_id).update_attributes(is_read: false)
9+
StoryRepository.fetch(@story_id).update!(is_read: false)
1110
end
1211
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
require_relative "../../repositories/story_repository"
22

33
class MarkAsUnstarred
4-
def initialize(story_id, repository = StoryRepository)
4+
def initialize(story_id)
55
@story_id = story_id
6-
@repo = repository
76
end
87

98
def mark_as_unstarred
10-
@repo.fetch(@story_id).update_attributes(is_starred: false)
9+
StoryRepository.fetch(@story_id).update!(is_starred: false)
1110
end
1211
end

spec/commands/stories/mark_as_read_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
describe MarkAsRead do
66
describe "#mark_as_read" do
7-
let(:story) { double }
8-
let(:repo) { double(fetch: story) }
7+
let(:story) { create_story(is_read: false) }
98

109
it "marks a story as read" do
11-
command = MarkAsRead.new(1, repo)
12-
expect(story).to receive(:update_attributes).with(is_read: true)
13-
command.mark_as_read
10+
expect { MarkAsRead.new(story.id).mark_as_read }
11+
.to change { Story.find(story.id).is_read }
12+
.to(true)
1413
end
1514
end
1615
end

spec/commands/stories/mark_as_starred_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
describe MarkAsStarred do
66
describe "#mark_as_starred" do
7-
let(:story) { double }
8-
let(:repo) { double(fetch: story) }
7+
let(:story) { create_story(is_starred: false) }
98

109
it "marks a story as starred" do
11-
command = MarkAsStarred.new(1, repo)
12-
expect(story).to receive(:update_attributes).with(is_starred: true)
13-
command.mark_as_starred
10+
expect { MarkAsStarred.new(story.id).mark_as_starred }
11+
.to change { Story.find(story.id).is_starred }
12+
.to(true)
1413
end
1514
end
1615
end

spec/commands/stories/mark_as_unread_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
describe MarkAsUnread do
66
describe "#mark_as_unread" do
7-
let(:story) { double }
8-
let(:repo) { double(fetch: story) }
7+
let(:story) { create_story(is_read: true) }
98

109
it "marks a story as unread" do
11-
command = MarkAsUnread.new(1, repo)
12-
expect(story).to receive(:update_attributes).with(is_read: false)
13-
command.mark_as_unread
10+
expect { MarkAsUnread.new(story.id).mark_as_unread }
11+
.to change { Story.find(story.id).is_read }
12+
.to(false)
1413
end
1514
end
1615
end

spec/commands/stories/mark_as_unstarred_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
describe MarkAsUnstarred do
66
describe "#mark_as_unstarred" do
7-
let(:story) { double }
8-
let(:repo) { double(fetch: story) }
7+
let(:story) { create_story(is_starred: true) }
98

109
it "marks a story as unstarred" do
11-
command = MarkAsUnstarred.new(1, repo)
12-
expect(story).to receive(:update_attributes).with(is_starred: false)
13-
command.mark_as_unstarred
10+
expect { MarkAsUnstarred.new(story.id).mark_as_unstarred }
11+
.to change { Story.find(story.id).is_starred }
12+
.to(false)
1413
end
1514
end
1615
end

0 commit comments

Comments
 (0)