Module: MuckEngine::Models::Matchers

Defined in:
lib/muck-engine/test/models/matchers.rb,
lib/muck-engine/test/models/matchers/sanitize_matcher.rb,
lib/muck-engine/test/models/matchers/muck_matcher_base.rb,
lib/muck-engine/test/models/matchers/scope_time_matchers.rb,
lib/muck-engine/test/models/matchers/scope_active_matchers.rb,
lib/muck-engine/test/models/matchers/scope_creator_matchers.rb,
lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb,
lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb,
lib/muck-engine/test/models/matchers/nested_attribute_matcher.rb,
lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb

Overview

it { should sanitize :title }

  it { should scope_sorted }
  it { should scope_sorted_id }
end

Defined Under Namespace

Classes: ActiveMatcher, CreatedByMatcher, IsPublicMatcher, MuckMatcherBase, NestedAttributeMatcher, OrdinalMatcher, SanitizeMatcher, SortingMatcher, TimeMatcher

Instance Method Summary collapse

Instance Method Details

#accept_nested_attributes_for(nested_model) ⇒ Object

Ensures that the model can accept nested attributes for the given model



6
7
8
# File 'lib/muck-engine/test/models/matchers/nested_attribute_matcher.rb', line 6

def accept_nested_attributes_for(nested_model)
  NestedAttributeMatcher.new(nested_model)
end

#sanitize(attribute) ⇒ Object

Ensures that the model sanitizes the given attributes



6
7
8
# File 'lib/muck-engine/test/models/matchers/sanitize_matcher.rb', line 6

def sanitize(attribute)
  SanitizeMatcher.new(attribute)
end

#scope_activeObject

‘active’ named scope which indicates whether an item is active or not requires that the class have a factory Tests:

scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }

Examples:

it { should scope_active }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_active_matchers.rb', line 11

def scope_active
  ActiveMatcher.new(:active)
end

#scope_by_creatorObject

Ensures that the model can scope by created_by requires that the class have a factory and that a user factory exist Tests:

scope :by_creator, lambda { |creator| where(['creator_id = ?', creator.id]) } }

Examples:

it { should scope_by_creator }


31
32
33
# File 'lib/muck-engine/test/models/matchers/scope_creator_matchers.rb', line 31

def scope_by_creator
  CreatedByMatcher.new(:by_creator, :creator)
end

#scope_by_latestObject

For ‘by_latest named scope which orders by updated at: Tests:

scope :by_latest, order("updated_at DESC")

Examples:

it { should scope_by_latest }


30
31
32
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 30

def scope_by_latest
  SortingMatcher.new(:by_latest, :updated_at)
end

#scope_by_nameObject

Test for ‘by_name’ named scope which orders by name requires that the class have a shoulda factory Tests:

scope :by_name, order("name ASC")

Examples:

it { should scope_by_name }


21
22
23
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 21

def scope_by_name
  SortingMatcher.new(:by_name, :name)
end

#scope_by_newestObject

Test for ‘by_newest’ named scope which orders by ‘created_at DESC’ requires that the class have a shoulda factory Tests:

scope :by_newest, order("created_at DESC")

Examples:

it { should scope_by_newest }


40
41
42
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 40

def scope_by_newest
  SortingMatcher.new(:by_newest, :created_at)
end

#scope_by_oldestObject

Test for ‘by_oldest’ named scope which orders by ‘created_at ASC’ requires that the class have a shoulda factory Tests:

scope :oldest, order("created_at ASC")

Examples:

it { should scope_oldest }


50
51
52
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 50

def scope_by_oldest
  SortingMatcher.new(:by_oldest, :created_at)
end

#scope_by_titleObject

Ensures that the model can sort by_title requires that the class have a factory Tests:

scope :by_title, order("title ASC")

Examples:

it { should scope_by_title }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 11

def scope_by_title
  SortingMatcher.new(:by_title, :title)
end

#scope_created_byObject

Ensures that the model can scope by created_by requires that the class have a factory and that a user factory exist Tests:

scope :created_by, lambda { |user| where(['user_id = ?', user.id]) } }

Examples:

it { should scope_created_by }


21
22
23
# File 'lib/muck-engine/test/models/matchers/scope_creator_matchers.rb', line 21

def scope_created_by
  CreatedByMatcher.new(:created_by, :user)
end

#scope_is_publicObject

‘is_public’ named scope which retrieves items that are marked public requires that the class have a factory Tests:

scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }

Examples:

it { should scope_is_public }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb', line 11

def scope_is_public
  IsPublicMatcher.new(:is_public)
end

#scope_newer_thanObject

‘newer_than’ named scope which retrieves items newer than given date requires that the class have a factory Tests:

scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }

Examples:

it { should scope_recent }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 11

def scope_newer_than
  TimeMatcher.new(:newer_than)
end

#scope_older_thanObject

‘scope_older_than’ named scope which retrieves items older than the given date requires that the class have a factory Tests:

scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }

Examples:

it { should scope_recent }


21
22
23
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 21

def scope_older_than
  TimeMatcher.new(:older_than)
end

#scope_sortedObject

Ensures that the model can sort by ‘sorted’ requires that the class have a factory Tests:

scope :sorted, order("sort ASC")

Examples:

it { should scope_sorted }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb', line 11

def scope_sorted
  OrdinalMatcher.new(:sorted, :sort)
end

#scope_sorted_idObject

it { should scope_sorted_id }



16
17
18
# File 'lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb', line 16

def scope_sorted_id
  OrdinalMatcher.new(:sorted_id, :sort)
end

#scope_sourceObject

Ensures that the model can scope by ‘source’ requires that the class have a factory and that a user factory exist Tests:

scope :created_by, lambda { |item_object| {:conditions => ["items.source_id = ? AND items.source_type = ?", item_object.id, item_object.class.to_s] } }

Examples:

it { should scope_created_by }


11
12
13
# File 'lib/muck-engine/test/models/matchers/scope_creator_matchers.rb', line 11

def scope_source
  CreatedByMatcher.new(:source, :source)
end