-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7fcddb
commit 6568869
Showing
5 changed files
with
70 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Write it! | ||
|
||
Teamtailor/NoHasManyInActiveModelSerializer: | ||
Teamtailor/NoEmbeddingsInActiveModelSerializer: | ||
Description: "TODO: Write a description of the cop." | ||
Enabled: true | ||
VersionAdded: "<<next>>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "teamtailor/no_has_many_in_active_model_serializer" | ||
require_relative "teamtailor/no_embeddings_in_active_model_serializer" |
66 changes: 66 additions & 0 deletions
66
spec/rubocop/cop/teamtailor/no_embeddings_in_active_model_serializer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Teamtailor::NoEmbeddingsInActiveModelSerializer, :config do | ||
let(:config) { RuboCop::Config.new } | ||
|
||
context "when in a serializer" do | ||
it "registers an offense when using `has_many`" do | ||
expect_offense(<<~RUBY) | ||
class FooSerializer < ActiveModel::Serializer | ||
has_many :locations, embed: :ids | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
end | ||
RUBY | ||
end | ||
|
||
it "registers an offense when using `has_one`" do | ||
expect_offense(<<~RUBY) | ||
class FooSerializer < ActiveModel::Serializer | ||
has_one :location, embed_in_root: true | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
end | ||
RUBY | ||
end | ||
|
||
it "registers offenses for all `has_many`" do | ||
expect_offense(<<~RUBY) | ||
class FooSerializer < ActiveModel::Serializer | ||
has_many :locations, embed: :ids | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
has_many :users, embed: :ids | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
end | ||
RUBY | ||
end | ||
|
||
it "registers offenses for both `has_many` and `has_one`" do | ||
expect_offense(<<~RUBY) | ||
class FooSerializer < ActiveModel::Serializer | ||
has_many :locations, embed: :ids | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
has_one :user, embed: :id | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ Teamtailor/NoEmbeddingsInActiveModelSerializer: No embedding of records | ||
end | ||
RUBY | ||
end | ||
|
||
it "does not register an offence when no has_one/has_many" do | ||
expect_no_offenses(<<~RUBY) | ||
class FooSerializer < ActiveModel::Serializer | ||
attributes :location_ids | ||
end | ||
RUBY | ||
end | ||
end | ||
|
||
context "when not in a serializer" do | ||
it "does not register an offense when using has_many" do | ||
expect_no_offenses(<<~RUBY) | ||
class Foo | ||
has_many :locations | ||
has_one :user | ||
end | ||
RUBY | ||
end | ||
end | ||
end |
45 changes: 0 additions & 45 deletions
45
spec/rubocop/cop/teamtailor/no_has_many_in_active_model_serializer_spec.rb
This file was deleted.
Oops, something went wrong.