Module: Graphiti::SpecHelpers::Matchers

Defined in:
lib/graphiti/spec_helpers/matchers.rb

Overview

Assertions against a resource's DSL. The schema specs cannot cover adapter-dependent options (primary key, foreign key, and so on) because the schema does not carry them; these read the resource config directly.

Defined Under Namespace

Classes: BaseMatcher, BelongsToMatcher, ExposeAttributeMatcher, FilterAttributeMatcher, HasManyMatcher, HasOneMatcher, RelationMatcher, ResourceDSLMatcher

Instance Method Summary collapse

Instance Method Details

#belong_to_resource(relation) ⇒ Object

Examples:

expect(subject).to belong_to_resource(:user)

expect(subject).to belong_to_resource(:user).with_options(foreign_key: :user_id, resource: UserResource)

expect(subject).not_to belong_to_resource(:user)

Parameters:

  • relation (Symbol)


153
154
155
# File 'lib/graphiti/spec_helpers/matchers.rb', line 153

def belong_to_resource(relation)
  BelongsToMatcher.new(relation)
end

#expose_attribute(attribute, type) ⇒ Object

Examples:

expect(subject).to expose_attribute(:name, :string)

expect(subject).to expose_attribute(:name, :string).with_options(writable: false)

expect(subject).not_to expose_attribute(:name, :string)

Parameters:

  • attribute (Symbol)
  • type (Symbol)


181
182
183
# File 'lib/graphiti/spec_helpers/matchers.rb', line 181

def expose_attribute(attribute, type)
  ExposeAttributeMatcher.new(attribute, type)
end

#filter_attribute(attribute, type) ⇒ Object

Examples:

expect(subject).to filter_attribute(:name, :string)

expect(subject).to filter_attribute(:name, :string).with_options(allow_nil: false)

expect(subject).not_to filter_attribute(:name, :string)

Parameters:

  • attribute (Symbol)
  • type (Symbol)


191
192
193
# File 'lib/graphiti/spec_helpers/matchers.rb', line 191

def filter_attribute(attribute, type)
  FilterAttributeMatcher.new(attribute, type)
end

#have_many_resources(relation) ⇒ Object

Examples:

expect(subject).to have_many_resources(:posts)

expect(subject).to have_many_resources(:posts).with_options(foreign_key: :post_id, resource: PostResource)

expect(subject).not_to have_many_resources(:posts)

Parameters:

  • relation (Symbol)


162
163
164
# File 'lib/graphiti/spec_helpers/matchers.rb', line 162

def have_many_resources(relation)
  HasManyMatcher.new(relation)
end

#have_one_resource(relation) ⇒ Object

Examples:

expect(subject).to have_one_resource(:post)

expect(subject).to have_one_resource(:post).with_options(foreign_key: :post_id, resource: PostResource)

expect(subject).not_to have_one_resource(:post)

Parameters:

  • relation (Symbol)


171
172
173
# File 'lib/graphiti/spec_helpers/matchers.rb', line 171

def have_one_resource(relation)
  HasOneMatcher.new(relation)
end