diff --git a/lib/cuprum/collections/basic/scopes/conjunction_scope.rb b/lib/cuprum/collections/basic/scopes/conjunction_scope.rb index a4622e5..0b151d5 100644 --- a/lib/cuprum/collections/basic/scopes/conjunction_scope.rb +++ b/lib/cuprum/collections/basic/scopes/conjunction_scope.rb @@ -2,14 +2,12 @@ require 'cuprum/collections/basic/scopes' require 'cuprum/collections/basic/scopes/base' -require 'cuprum/collections/scopes/composition/conjunction' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/conjunction' module Cuprum::Collections::Basic::Scopes # Scope for filtering data matching all of the given scopes. class ConjunctionScope < Cuprum::Collections::Basic::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Conjunction + include Cuprum::Collections::Scopes::Conjunction # Returns true if the provided item matches all of the configured scopes. def match?(item:) @@ -18,10 +16,5 @@ def match?(item:) scopes.all? { |scope| scope.match?(item: item) } end alias matches? match? - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :conjunction - end end end diff --git a/lib/cuprum/collections/basic/scopes/criteria_scope.rb b/lib/cuprum/collections/basic/scopes/criteria_scope.rb index a1caa0e..c48a753 100644 --- a/lib/cuprum/collections/basic/scopes/criteria_scope.rb +++ b/lib/cuprum/collections/basic/scopes/criteria_scope.rb @@ -3,14 +3,12 @@ require 'cuprum/collections/basic/scopes' require 'cuprum/collections/basic/scopes/base' require 'cuprum/collections/queries' -require 'cuprum/collections/scopes/composition/criteria' require 'cuprum/collections/scopes/criteria' module Cuprum::Collections::Basic::Scopes # Scope for filtering on basic collection data based on criteria. class CriteriaScope < Cuprum::Collections::Basic::Scopes::Base include Cuprum::Collections::Scopes::Criteria - include Cuprum::Collections::Scopes::Composition::Criteria Operators = Cuprum::Collections::Queries::Operators private_constant :Operators diff --git a/lib/cuprum/collections/basic/scopes/disjunction_scope.rb b/lib/cuprum/collections/basic/scopes/disjunction_scope.rb index 8e8b206..65182e7 100644 --- a/lib/cuprum/collections/basic/scopes/disjunction_scope.rb +++ b/lib/cuprum/collections/basic/scopes/disjunction_scope.rb @@ -2,14 +2,12 @@ require 'cuprum/collections/basic/scopes' require 'cuprum/collections/basic/scopes/base' -require 'cuprum/collections/scopes/composition/disjunction' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/disjunction' module Cuprum::Collections::Basic::Scopes # Scope for filtering data matching any of the given scopes. class DisjunctionScope < Cuprum::Collections::Basic::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Disjunction + include Cuprum::Collections::Scopes::Disjunction # Returns true if the provided item matches any of the configured scopes. def match?(item:) @@ -18,10 +16,5 @@ def match?(item:) scopes.any? { |scope| scope.match?(item: item) } end alias matches? match? - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :disjunction - end end end diff --git a/lib/cuprum/collections/basic/scopes/negation_scope.rb b/lib/cuprum/collections/basic/scopes/negation_scope.rb index c502795..f7427a9 100644 --- a/lib/cuprum/collections/basic/scopes/negation_scope.rb +++ b/lib/cuprum/collections/basic/scopes/negation_scope.rb @@ -2,14 +2,12 @@ require 'cuprum/collections/basic/scopes' require 'cuprum/collections/basic/scopes/base' -require 'cuprum/collections/scopes/composition/negation' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/negation' module Cuprum::Collections::Basic::Scopes # Scope for filtering data not matching at least one of the given scopes. class NegationScope < Cuprum::Collections::Basic::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Negation + include Cuprum::Collections::Scopes::Negation # Returns true if the provided item does not match at least one scope. def match?(item:) @@ -18,10 +16,5 @@ def match?(item:) scopes.any? { |scope| !scope.match?(item: item) } end alias matches? match? - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :negation - end end end diff --git a/lib/cuprum/collections/scopes.rb b/lib/cuprum/collections/scopes.rb index 9cc165d..2e12385 100644 --- a/lib/cuprum/collections/scopes.rb +++ b/lib/cuprum/collections/scopes.rb @@ -9,10 +9,13 @@ module Scopes autoload :Builder, 'cuprum/collections/scopes/builder' autoload :Collection, 'cuprum/collections/scopes/collection' autoload :Composition, 'cuprum/collections/scopes/composition' + autoload :Conjunction, 'cuprum/collections/scopes/conjunction' autoload :ConjunctionScope, 'cuprum/collections/scopes/conjunction_scope' autoload :Criteria, 'cuprum/collections/scopes/criteria' autoload :CriteriaScope, 'cuprum/collections/scopes/criteria_scope' + autoload :Disjunction, 'cuprum/collections/scopes/disjunction' autoload :DisjunctionScope, 'cuprum/collections/scopes/disjunction_scope' + autoload :Negation, 'cuprum/collections/scopes/negation' autoload :NegationScope, 'cuprum/collections/scopes/negation_scope' end end diff --git a/lib/cuprum/collections/scopes/composition.rb b/lib/cuprum/collections/scopes/composition.rb index 1cb8093..c410f33 100644 --- a/lib/cuprum/collections/scopes/composition.rb +++ b/lib/cuprum/collections/scopes/composition.rb @@ -5,11 +5,6 @@ module Cuprum::Collections::Scopes # Defines a fluent interface for composing scopes. module Composition - autoload :Conjunction, 'cuprum/collections/scopes/composition/conjunction' - autoload :Criteria, 'cuprum/collections/scopes/composition/criteria' - autoload :Disjunction, 'cuprum/collections/scopes/composition/disjunction' - autoload :Negation, 'cuprum/collections/scopes/composition/negation' - # @override and(hash = nil, &block) # Parses the hash or block and combines using a logical AND. # diff --git a/lib/cuprum/collections/scopes/composition/criteria.rb b/lib/cuprum/collections/scopes/composition/criteria.rb deleted file mode 100644 index 83314c9..0000000 --- a/lib/cuprum/collections/scopes/composition/criteria.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require 'cuprum/collections/scopes/composition' -require 'cuprum/collections/scopes/criteria' - -module Cuprum::Collections::Scopes::Composition - # Defines composition behavior for criteria scopes. - module Criteria - include Cuprum::Collections::Scopes::Composition - - # (see Cuprum::Collections::Scopes::Composition#and) - def and(*args, &block) - return and_criteria_scope(args.first) if criteria_scope?(args.first) - - return super if scope?(args.first) - - with_criteria([*criteria, *self.class.parse(*args, &block)]) - end - alias where and - - private - - def and_criteria_scope(scope) - with_criteria([*criteria, *scope.criteria]) - end - end -end diff --git a/lib/cuprum/collections/scopes/composition/conjunction.rb b/lib/cuprum/collections/scopes/conjunction.rb similarity index 78% rename from lib/cuprum/collections/scopes/composition/conjunction.rb rename to lib/cuprum/collections/scopes/conjunction.rb index 0d47061..c61f58a 100644 --- a/lib/cuprum/collections/scopes/composition/conjunction.rb +++ b/lib/cuprum/collections/scopes/conjunction.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require 'cuprum/collections/scopes/composition' +require 'cuprum/collections/scopes' +require 'cuprum/collections/scopes/container' -module Cuprum::Collections::Scopes::Composition - # Defines composition behavior for conjunction scopes. +module Cuprum::Collections::Scopes + # Functionality for implementing a logical AND scope. module Conjunction - include Cuprum::Collections::Scopes::Composition + include Cuprum::Collections::Scopes::Container # (see Cuprum::Collections::Scopes::Composition#and) def and(*args, &block) @@ -25,6 +26,11 @@ def not(*args, &block) with_scopes([*scopes, inverted]) end + # (see Cuprum::Collections::Scopes::Base#type) + def type + :conjunction + end + private def and_conjunction_scope(scope) diff --git a/lib/cuprum/collections/scopes/conjunction_scope.rb b/lib/cuprum/collections/scopes/conjunction_scope.rb index 4db8805..604281c 100644 --- a/lib/cuprum/collections/scopes/conjunction_scope.rb +++ b/lib/cuprum/collections/scopes/conjunction_scope.rb @@ -2,18 +2,11 @@ require 'cuprum/collections/scopes' require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/conjunction' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/conjunction' module Cuprum::Collections::Scopes # Generic scope class for defining collection-independent logical AND scopes. class ConjunctionScope < Cuprum::Collections::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Conjunction - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :conjunction - end + include Cuprum::Collections::Scopes::Conjunction end end diff --git a/lib/cuprum/collections/scopes/criteria.rb b/lib/cuprum/collections/scopes/criteria.rb index a285742..6e0f6c1 100644 --- a/lib/cuprum/collections/scopes/criteria.rb +++ b/lib/cuprum/collections/scopes/criteria.rb @@ -241,6 +241,16 @@ def initialize(criteria:, **options) # @return [Array] the criteria used for filtering query data. attr_reader :criteria + # (see Cuprum::Collections::Scopes::Composition#and) + def and(*args, &block) + return and_criteria_scope(args.first) if criteria_scope?(args.first) + + return super if scope?(args.first) + + with_criteria([*criteria, *self.class.parse(*args, &block)]) + end + alias where and + # (see Cuprum::Collections::Scopes::Base#type) def type :criteria @@ -258,5 +268,11 @@ def with_criteria(criteria) protected attr_writer :criteria + + private + + def and_criteria_scope(scope) + with_criteria([*criteria, *scope.criteria]) + end end end diff --git a/lib/cuprum/collections/scopes/criteria_scope.rb b/lib/cuprum/collections/scopes/criteria_scope.rb index d099437..2fb786a 100644 --- a/lib/cuprum/collections/scopes/criteria_scope.rb +++ b/lib/cuprum/collections/scopes/criteria_scope.rb @@ -2,12 +2,10 @@ require 'cuprum/collections/scopes' require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/criteria' require 'cuprum/collections/scopes/criteria' module Cuprum::Collections::Scopes class CriteriaScope < Cuprum::Collections::Scopes::Base include Cuprum::Collections::Scopes::Criteria - include Cuprum::Collections::Scopes::Composition::Criteria end end diff --git a/lib/cuprum/collections/scopes/composition/disjunction.rb b/lib/cuprum/collections/scopes/disjunction.rb similarity index 60% rename from lib/cuprum/collections/scopes/composition/disjunction.rb rename to lib/cuprum/collections/scopes/disjunction.rb index 9da621c..be6f655 100644 --- a/lib/cuprum/collections/scopes/composition/disjunction.rb +++ b/lib/cuprum/collections/scopes/disjunction.rb @@ -1,10 +1,13 @@ # frozen_string_literal: true -require 'cuprum/collections/scopes/composition' +require 'cuprum/collections/scopes' +require 'cuprum/collections/scopes/container' -module Cuprum::Collections::Scopes::Composition - # Defines composition behavior for disjunction scopes. +module Cuprum::Collections::Scopes + # Functionality for implementing a logical OR scope. module Disjunction + include Cuprum::Collections::Scopes::Container + # (see Cuprum::Collections::Scopes::Composition#or) def or(*args, &block) return or_disjuncton_scope(args.first) if disjunction_scope?(args.first) @@ -12,6 +15,11 @@ def or(*args, &block) with_scopes([*scopes, builder.build(*args, &block)]) end + # (see Cuprum::Collections::Scopes::Base#type) + def type + :disjunction + end + private def or_disjuncton_scope(scope) diff --git a/lib/cuprum/collections/scopes/disjunction_scope.rb b/lib/cuprum/collections/scopes/disjunction_scope.rb index ff08af2..098a58b 100644 --- a/lib/cuprum/collections/scopes/disjunction_scope.rb +++ b/lib/cuprum/collections/scopes/disjunction_scope.rb @@ -2,18 +2,11 @@ require 'cuprum/collections/scopes' require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/disjunction' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/disjunction' module Cuprum::Collections::Scopes # Generic scope class for defining collection-independent logical OR scopes. class DisjunctionScope < Cuprum::Collections::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Disjunction - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :disjunction - end + include Cuprum::Collections::Scopes::Disjunction end end diff --git a/lib/cuprum/collections/scopes/composition/negation.rb b/lib/cuprum/collections/scopes/negation.rb similarity index 69% rename from lib/cuprum/collections/scopes/composition/negation.rb rename to lib/cuprum/collections/scopes/negation.rb index dccd5eb..280bc8c 100644 --- a/lib/cuprum/collections/scopes/composition/negation.rb +++ b/lib/cuprum/collections/scopes/negation.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require 'cuprum/collections/scopes/composition' +require 'cuprum/collections/scopes' +require 'cuprum/collections/scopes/container' -module Cuprum::Collections::Scopes::Composition - # Defines composition behavior for negation scopes. +module Cuprum::Collections::Scopes + # Functionality for implementing a logical NAND scope. module Negation - include Cuprum::Collections::Scopes::Composition + include Cuprum::Collections::Scopes::Container # (see Cuprum::Collections::Scopes::Composition#and) def and(*args, &block) @@ -31,5 +32,10 @@ def not(*args, &block) builder.build_conjunction_scope(scopes: scopes) end + + # (see Cuprum::Collections::Scopes::Base#type) + def type + :negation + end end end diff --git a/lib/cuprum/collections/scopes/negation_scope.rb b/lib/cuprum/collections/scopes/negation_scope.rb index 0499a72..9906dcc 100644 --- a/lib/cuprum/collections/scopes/negation_scope.rb +++ b/lib/cuprum/collections/scopes/negation_scope.rb @@ -2,18 +2,11 @@ require 'cuprum/collections/scopes' require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/negation' -require 'cuprum/collections/scopes/container' +require 'cuprum/collections/scopes/negation' module Cuprum::Collections::Scopes # Generic scope class for defining collection-independent logical NAND scopes. class NegationScope < Cuprum::Collections::Scopes::Base - include Cuprum::Collections::Scopes::Container - include Cuprum::Collections::Scopes::Composition::Negation - - # (see Cuprum::Collections::Scopes::Base#type) - def type - :negation - end + include Cuprum::Collections::Scopes::Negation end end diff --git a/spec/cuprum/collections/scopes/composition/conjunction_spec.rb b/spec/cuprum/collections/scopes/composition/conjunction_spec.rb deleted file mode 100644 index e66e050..0000000 --- a/spec/cuprum/collections/scopes/composition/conjunction_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require 'cuprum/collections/rspec/contracts/scopes/composition_contracts' -require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/conjunction' -require 'cuprum/collections/scopes/container' -require 'cuprum/collections/scopes/criteria_scope' - -RSpec.describe Cuprum::Collections::Scopes::Composition::Conjunction do - include Cuprum::Collections::RSpec::Contracts::Scopes::CompositionContracts - - subject(:scope) { described_class.new(scopes: scopes) } - - let(:described_class) { Spec::ExampleScope } - let(:scopes) { [] } - - example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ - do |klass| - klass.include Cuprum::Collections::Scopes::Container - klass.include Cuprum::Collections::Scopes::Composition::Conjunction # rubocop:disable RSpec/DescribedClass - - klass.define_method(:type) { :conjunction } - end - - def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope - - if block_given? - scope_class.build(&block) - else - scope_class.build(filters) - end - end - - include_contract 'should compose scopes for conjunction' -end diff --git a/spec/cuprum/collections/scopes/composition/criteria_spec.rb b/spec/cuprum/collections/scopes/composition/criteria_spec.rb deleted file mode 100644 index 902467d..0000000 --- a/spec/cuprum/collections/scopes/composition/criteria_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'cuprum/collections/rspec/contracts/scopes/composition_contracts' -require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/criteria' -require 'cuprum/collections/scopes/criteria' -require 'cuprum/collections/scopes/criteria_scope' - -RSpec.describe Cuprum::Collections::Scopes::Composition::Criteria do - include Cuprum::Collections::RSpec::Contracts::Scopes::CompositionContracts - - subject(:scope) { described_class.new(criteria: criteria) } - - let(:described_class) { Spec::ExampleScope } - let(:criteria) { [] } - - example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ - do |klass| - klass.include Cuprum::Collections::Scopes::Criteria - klass.include Cuprum::Collections::Scopes::Composition::Criteria # rubocop:disable RSpec/DescribedClass - - klass.define_method(:type) { :criteria } - end - - include_contract 'should compose scopes for criteria' -end diff --git a/spec/cuprum/collections/scopes/composition/disjunction_spec.rb b/spec/cuprum/collections/scopes/composition/disjunction_spec.rb deleted file mode 100644 index 446a59c..0000000 --- a/spec/cuprum/collections/scopes/composition/disjunction_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require 'cuprum/collections/rspec/contracts/scopes/composition_contracts' -require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/disjunction' -require 'cuprum/collections/scopes/container' -require 'cuprum/collections/scopes/criteria_scope' - -RSpec.describe Cuprum::Collections::Scopes::Composition::Disjunction do - include Cuprum::Collections::RSpec::Contracts::Scopes::CompositionContracts - - subject(:scope) { described_class.new(scopes: scopes) } - - let(:described_class) { Spec::ExampleScope } - let(:scopes) { [] } - - example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ - do |klass| - klass.include Cuprum::Collections::Scopes::Container - klass.include Cuprum::Collections::Scopes::Composition::Disjunction # rubocop:disable RSpec/DescribedClass - - klass.define_method(:type) { :disjunction } - end - - def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope - - if block_given? - scope_class.build(&block) - else - scope_class.build(filters) - end - end - - include_contract 'should compose scopes for disjunction' -end diff --git a/spec/cuprum/collections/scopes/composition/negation_spec.rb b/spec/cuprum/collections/scopes/composition/negation_spec.rb deleted file mode 100644 index f63711e..0000000 --- a/spec/cuprum/collections/scopes/composition/negation_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require 'cuprum/collections/rspec/contracts/scopes/composition_contracts' -require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/negation' -require 'cuprum/collections/scopes/container' -require 'cuprum/collections/scopes/criteria_scope' - -RSpec.describe Cuprum::Collections::Scopes::Composition::Negation do - include Cuprum::Collections::RSpec::Contracts::Scopes::CompositionContracts - - subject(:scope) { described_class.new(scopes: scopes) } - - let(:described_class) { Spec::ExampleScope } - let(:scopes) { [] } - - example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ - do |klass| - klass.include Cuprum::Collections::Scopes::Container - klass.include Cuprum::Collections::Scopes::Composition::Negation # rubocop:disable RSpec/DescribedClass - - klass.define_method(:type) { :negation } - end - - def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope - - if block_given? - scope_class.build(&block) - else - scope_class.build(filters) - end - end - - include_contract 'should compose scopes for negation' -end diff --git a/spec/cuprum/collections/scopes/conjunction_scope_spec.rb b/spec/cuprum/collections/scopes/conjunction_scope_spec.rb index d563636..e326f3e 100644 --- a/spec/cuprum/collections/scopes/conjunction_scope_spec.rb +++ b/spec/cuprum/collections/scopes/conjunction_scope_spec.rb @@ -12,7 +12,7 @@ let(:scopes) { [] } def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope + scope_class = Cuprum::Collections::Scopes::CriteriaScope if block_given? scope_class.build(&block) diff --git a/spec/cuprum/collections/scopes/conjunction_spec.rb b/spec/cuprum/collections/scopes/conjunction_spec.rb new file mode 100644 index 0000000..3b48c15 --- /dev/null +++ b/spec/cuprum/collections/scopes/conjunction_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'cuprum/collections/rspec/contracts/scopes/logical_contracts' +require 'cuprum/collections/scopes/base' +require 'cuprum/collections/scopes/conjunction' +require 'cuprum/collections/scopes/criteria_scope' + +RSpec.describe Cuprum::Collections::Scopes::Conjunction do + include Cuprum::Collections::RSpec::Contracts::Scopes::LogicalContracts + + subject(:scope) { described_class.new(scopes: scopes) } + + let(:described_class) { Spec::ExampleScope } + let(:scopes) { [] } + + example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ + do |klass| + klass.include Cuprum::Collections::Scopes::Conjunction # rubocop:disable RSpec/DescribedClass + end + + def build_scope(filters = nil, &block) + scope_class = Cuprum::Collections::Scopes::CriteriaScope + + if block_given? + scope_class.build(&block) + else + scope_class.build(filters) + end + end + + include_contract 'should be a conjunction scope', abstract: true +end diff --git a/spec/cuprum/collections/scopes/criteria_spec.rb b/spec/cuprum/collections/scopes/criteria_spec.rb index f56fc10..f0bfeb1 100644 --- a/spec/cuprum/collections/scopes/criteria_spec.rb +++ b/spec/cuprum/collections/scopes/criteria_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'cuprum/collections/scopes/base' -require 'cuprum/collections/scopes/composition/criteria' require 'cuprum/collections/scopes/criteria' require 'cuprum/collections/rspec/contracts/scopes/criteria_contracts' @@ -15,7 +14,6 @@ example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ do |klass| klass.include Cuprum::Collections::Scopes::Criteria # rubocop:disable RSpec/DescribedClass - klass.include Cuprum::Collections::Scopes::Composition::Criteria end describe '::Parser' do diff --git a/spec/cuprum/collections/scopes/disjunction_scope_spec.rb b/spec/cuprum/collections/scopes/disjunction_scope_spec.rb index 0c9f039..3741455 100644 --- a/spec/cuprum/collections/scopes/disjunction_scope_spec.rb +++ b/spec/cuprum/collections/scopes/disjunction_scope_spec.rb @@ -12,7 +12,7 @@ let(:scopes) { [] } def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope + scope_class = Cuprum::Collections::Scopes::CriteriaScope if block_given? scope_class.build(&block) diff --git a/spec/cuprum/collections/scopes/disjunction_spec.rb b/spec/cuprum/collections/scopes/disjunction_spec.rb new file mode 100644 index 0000000..f9f79d0 --- /dev/null +++ b/spec/cuprum/collections/scopes/disjunction_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'cuprum/collections/rspec/contracts/scopes/logical_contracts' +require 'cuprum/collections/scopes/base' +require 'cuprum/collections/scopes/criteria_scope' +require 'cuprum/collections/scopes/disjunction' + +RSpec.describe Cuprum::Collections::Scopes::Disjunction do + include Cuprum::Collections::RSpec::Contracts::Scopes::LogicalContracts + + subject(:scope) { described_class.new(scopes: scopes) } + + let(:described_class) { Spec::ExampleScope } + let(:scopes) { [] } + + example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ + do |klass| + klass.include Cuprum::Collections::Scopes::Disjunction # rubocop:disable RSpec/DescribedClass + end + + def build_scope(filters = nil, &block) + scope_class = Cuprum::Collections::Scopes::CriteriaScope + + if block_given? + scope_class.build(&block) + else + scope_class.build(filters) + end + end + + include_contract 'should be a disjunction scope', abstract: true +end diff --git a/spec/cuprum/collections/scopes/negation_scope_spec.rb b/spec/cuprum/collections/scopes/negation_scope_spec.rb index f7d6c3a..64ea0d2 100644 --- a/spec/cuprum/collections/scopes/negation_scope_spec.rb +++ b/spec/cuprum/collections/scopes/negation_scope_spec.rb @@ -12,7 +12,7 @@ let(:scopes) { [] } def build_scope(filters = nil, &block) - scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope + scope_class = Cuprum::Collections::Scopes::CriteriaScope if block_given? scope_class.build(&block) diff --git a/spec/cuprum/collections/scopes/negation_spec.rb b/spec/cuprum/collections/scopes/negation_spec.rb new file mode 100644 index 0000000..1ea3171 --- /dev/null +++ b/spec/cuprum/collections/scopes/negation_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'cuprum/collections/rspec/contracts/scopes/logical_contracts' +require 'cuprum/collections/scopes/base' +require 'cuprum/collections/scopes/criteria_scope' +require 'cuprum/collections/scopes/negation' + +RSpec.describe Cuprum::Collections::Scopes::Negation do + include Cuprum::Collections::RSpec::Contracts::Scopes::LogicalContracts + + subject(:scope) { described_class.new(scopes: scopes) } + + let(:described_class) { Spec::ExampleScope } + let(:scopes) { [] } + + example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ + do |klass| + klass.include Cuprum::Collections::Scopes::Negation # rubocop:disable RSpec/DescribedClass + end + + def build_scope(filters = nil, &block) + scope_class = Cuprum::Collections::Scopes::CriteriaScope + + if block_given? + scope_class.build(&block) + else + scope_class.build(filters) + end + end + + include_contract 'should be a negation scope', abstract: true +end