public
Description: Some testing macros for the Shoulda plugin/gem.
Homepage: http://soyunperdedor.com/
Clone URL: git://github.com/mileszs/shoulda_macros.git
shoulda_macros / plugins.rb
100644 66 lines (50 sloc) 2.296 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Test::Unit::TestCase
 
  # Shoulda helper for testing Paperclip
  def self.should_have_attached_file(attachment)
    klass = self.name.gsub(/Test$/, '').constantize
 
    context "To support a paperclip attachment named #{attachment}, #{klass}" do
      should_have_db_column("#{attachment}_file_name", :type => :string)
      should_have_db_column("#{attachment}_content_type", :type => :string)
      should_have_db_column("#{attachment}_file_size", :type => :integer)
    end
 
    should "have a paperclip attachment named ##{attachment}" do
      assert klass.new.respond_to?(attachment.to_sym),
             "@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
      assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
    end
  end
 
  # Shoulda helper for acts_as_taggable_on_steroids
  def self.should_act_as_taggable_on_steroids
    klass = self.name.gsub(/Test$/, '').constantize
 
    should "include ActsAsTaggableOnSteroids methods" do
      assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::ClassMethods)
      assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::SingletonMethods)
      assert klass.include?(ActiveRecord::Acts::Taggable::InstanceMethods)
    end
 
    should_have_many :taggings, :tags
  end
 
  def self.should_act_as_ferret(*fields)
    klass = self.name.gsub(/Test$/, '').constantize
 
    should "include ActsAsFerret methods" do
      assert klass.extended_by.include?(ActsAsFerret::ClassMethods)
      assert klass.include?(ActsAsFerret::InstanceMethods)
      assert klass.include?(ActsAsFerret::MoreLikeThis::InstanceMethods)
      assert klass.include?(ActsAsFerret::ResultAttributes)
    end
 
    fields.each do |f|
      should "create an index for field named #{f}" do
        assert klass.aaf_configuration[:fields].include?(f)
      end
    end
  end
 
  def self.should_act_as_list
    klass = self.name.gsub(/Test$/, '').constantize
 
    context "To support acts_as_list" do
      should_have_db_column('position', :type => :integer)
    end
 
    should "include ActsAsList methods" do
      assert klass.include?(ActiveRecord::Acts::List::InstanceMethods)
    end
 
    should_have_instance_methods :acts_as_list_class, :position_column, :scope_condition
  end
 
end