-
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.
Implement Associations::HasOne, HasMany.
- Loading branch information
1 parent
b1e7634
commit b3a81ce
Showing
4 changed files
with
100 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/association' | ||
require 'cuprum/collections/associations' | ||
|
||
module Cuprum::Collections::Associations | ||
# Object representing a has_many association. | ||
class HasMany < Cuprum::Collections::Association | ||
# (see Cuprum::Collections::Association#initialize) | ||
def initialize(**params) | ||
params.delete(:plural) | ||
params.delete(:singular) | ||
|
||
super(**params, singular: false) | ||
end | ||
|
||
private | ||
|
||
def ignored_parameters | ||
@ignored_parameters ||= Set.new(IGNORED_PARAMETERS + %i[singular]) | ||
end | ||
end | ||
end |
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/association' | ||
require 'cuprum/collections/associations' | ||
|
||
module Cuprum::Collections::Associations | ||
# Object representing a has_one association. | ||
class HasOne < Cuprum::Collections::Association | ||
# (see Cuprum::Collections::Association#initialize) | ||
def initialize(**params) | ||
params.delete(:plural) | ||
params.delete(:singular) | ||
|
||
super(**params, singular: true) | ||
end | ||
|
||
private | ||
|
||
def ignored_parameters | ||
@ignored_parameters ||= Set.new(IGNORED_PARAMETERS + %i[singular]) | ||
end | ||
end | ||
end |
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/associations/has_many' | ||
require 'cuprum/collections/rspec/contracts/association_contracts' | ||
|
||
require 'support/book' | ||
require 'support/grimoire' | ||
require 'support/scoped_book' | ||
|
||
RSpec.describe Cuprum::Collections::Associations::HasMany do | ||
include Cuprum::Collections::RSpec::Contracts::AssociationContracts | ||
|
||
subject(:association) { described_class.new(**constructor_options) } | ||
|
||
let(:name) { 'books' } | ||
let(:constructor_options) { { name: name } } | ||
|
||
include_contract 'should be a has association' | ||
|
||
describe '#plural?' do | ||
it { expect(association.plural?).to be true } | ||
end | ||
|
||
describe '#singular?' do | ||
it { expect(association.singular?).to be false } | ||
end | ||
end |
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/associations/has_one' | ||
require 'cuprum/collections/rspec/contracts/association_contracts' | ||
|
||
require 'support/book' | ||
require 'support/grimoire' | ||
require 'support/scoped_book' | ||
|
||
RSpec.describe Cuprum::Collections::Associations::HasOne do | ||
include Cuprum::Collections::RSpec::Contracts::AssociationContracts | ||
|
||
subject(:association) { described_class.new(**constructor_options) } | ||
|
||
let(:name) { 'book' } | ||
let(:constructor_options) { { name: name } } | ||
|
||
include_contract 'should be a has association' | ||
|
||
describe '#plural?' do | ||
it { expect(association.plural?).to be false } | ||
end | ||
|
||
describe '#singular?' do | ||
it { expect(association.singular?).to be true } | ||
end | ||
end |