module Suit::Models::Matchers
it { should sanitize :title } it { should scope_sorted } it { should scope_sorted_id }
end
Public Instance Methods
Ensures that the model can accept nested attributes for the given model
# File lib/models/matchers/nested_attribute_matcher.rb, line 6 def accept_nested_attributes_for(nested_model) NestedAttributeMatcher.new(nested_model) end
Ensures that the model sanitizes the given attributes
# File lib/models/matchers/sanitize_matcher.rb, line 6 def sanitize(attribute) SanitizeMatcher.new(attribute) end
'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 }
# File lib/models/matchers/scope_active_matchers.rb, line 11 def scope_active ActiveMatcher.new(:active) end
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 }
# File lib/models/matchers/scope_creator_matchers.rb, line 31 def scope_by_creator CreatedByMatcher.new(:by_creator, :creator) end
For 'by_latest named scope which orders by updated at: Tests:
scope :by_latest, order("updated_at DESC")
Examples:
it { should scope_by_latest }
# File lib/models/matchers/scope_sorting_matchers.rb, line 30 def scope_by_latest SortingMatcher.new(:by_latest, :updated_at) end
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 }
# File lib/models/matchers/scope_sorting_matchers.rb, line 21 def scope_by_name SortingMatcher.new(:by_name, :name) end
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 }
# File lib/models/matchers/scope_sorting_matchers.rb, line 40 def scope_by_newest SortingMatcher.new(:by_newest, :created_at) end
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 }
# File lib/models/matchers/scope_sorting_matchers.rb, line 50 def scope_by_oldest SortingMatcher.new(:by_oldest, :created_at) end
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 }
# File lib/models/matchers/scope_sorting_matchers.rb, line 11 def scope_by_title SortingMatcher.new(:by_title, :title) end
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 }
# File lib/models/matchers/scope_creator_matchers.rb, line 21 def scope_created_by CreatedByMatcher.new(:created_by, :user) end
'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 }
# File lib/models/matchers/scope_is_public_matchers.rb, line 11 def scope_is_public IsPublicMatcher.new(:is_public) end
'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 }
# File lib/models/matchers/scope_time_matchers.rb, line 11 def scope_newer_than TimeMatcher.new(:newer_than) end
'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 }
# File lib/models/matchers/scope_time_matchers.rb, line 21 def scope_older_than TimeMatcher.new(:older_than) end
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 }
# File lib/models/matchers/scope_ordinal_matchers.rb, line 11 def scope_sorted OrdinalMatcher.new(:sorted, :sort) end
it { should scope_sorted_id
}
# File lib/models/matchers/scope_ordinal_matchers.rb, line 16 def scope_sorted_id OrdinalMatcher.new(:sorted_id, :sort) end
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 }
# File lib/models/matchers/scope_creator_matchers.rb, line 11 def scope_source CreatedByMatcher.new(:source, :source) end