seanhussey-woulda 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +75 -0
- data/Rakefile +5 -5
- data/lib/woulda/acts_as_ferret/macros.rb +24 -0
- data/lib/woulda/acts_as_ferret.rb +6 -0
- data/lib/woulda/acts_as_list/macros.rb +20 -0
- data/lib/woulda/acts_as_list.rb +6 -0
- data/lib/woulda/acts_as_paranoid/macros.rb +39 -0
- data/lib/woulda/acts_as_paranoid.rb +6 -0
- data/lib/woulda/acts_as_solr/macros.rb +30 -0
- data/lib/woulda/acts_as_solr.rb +6 -0
- data/lib/woulda/acts_as_taggable_on_steroids/macros.rb +18 -0
- data/lib/woulda/acts_as_taggable_on_steroids.rb +6 -0
- data/lib/woulda/attachment_fu/macros.rb +27 -0
- data/lib/woulda/attachment_fu.rb +6 -0
- data/lib/woulda/enumerations_mixin/macros.rb +26 -0
- data/lib/woulda/enumerations_mixin.rb +6 -0
- data/lib/woulda/paperclip/macros.rb +22 -0
- data/lib/woulda/paperclip.rb +6 -0
- data/lib/woulda/will_paginate/macros.rb +18 -0
- data/lib/woulda/will_paginate.rb +6 -0
- data/lib/woulda.rb +9 -0
- data/shoulda_macros/woulda_macros.rb +1 -0
- metadata +37 -5
- data/README +0 -0
- data/shoulda_macros/should_act_as_paranoid.rb +0 -33
data/README.textile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
h1. woulda
|
2
|
+
|
3
|
+
Testing is love. Especially when done with "Shoulda":http://thoughtbot.com/projects/shoulda. Shoulda makes testing your Rails app pretty easy.
|
4
|
+
|
5
|
+
There are tons of Rails plugins and gems out there. It should be easy to test your Rails app that uses these as well. That kind of support doesn't really belong in Shoulda itself, though.
|
6
|
+
|
7
|
+
That's where Woulda comes in.
|
8
|
+
|
9
|
+
h2. Installing
|
10
|
+
|
11
|
+
It's available as a gem: <pre>gem install seanhussey-woulda --source http://gems.github.com</pre>
|
12
|
+
|
13
|
+
Use it in a Rails app by placing in config/environments/test.rb:
|
14
|
+
|
15
|
+
<pre>config.gem 'seanhussey-woulda', :lib => 'woulda', :source => 'http://gems.github.com'</pre>
|
16
|
+
|
17
|
+
Woulda requires "shoulda":http://github.com/thoughtbot/shoulda/tree/master >= 2.0.0.
|
18
|
+
|
19
|
+
h2. Included Macros
|
20
|
+
|
21
|
+
<pre><code># acts_as_ferret
|
22
|
+
class PostTest < Test::Unit::TestCase
|
23
|
+
should_act_as_ferret :title, :contents
|
24
|
+
end
|
25
|
+
|
26
|
+
# acts_as_list
|
27
|
+
class NewsItemTest < Test::Unit::TestCase
|
28
|
+
should_act_as_list
|
29
|
+
end
|
30
|
+
|
31
|
+
# acts_as_paranoid
|
32
|
+
class DocumentTest < Test::Unit::TestCase
|
33
|
+
should_act_as_paranoid
|
34
|
+
end
|
35
|
+
|
36
|
+
# acts_as_taggable_on_steroids
|
37
|
+
class PersonTest < Test::Unit::TestCase
|
38
|
+
should_act_as_taggable_on_steroids
|
39
|
+
|
40
|
+
# attachment_fu
|
41
|
+
class ImageTest < Test::Unit::TestCase
|
42
|
+
should_have_attachment :content_type => :image
|
43
|
+
end
|
44
|
+
|
45
|
+
# enumeration_mixin
|
46
|
+
class RoleTest < Test::Unit::
|
47
|
+
should_act_as_enumerated
|
48
|
+
end
|
49
|
+
|
50
|
+
# paperclip
|
51
|
+
class UserTest < Test::Unit::TestCase
|
52
|
+
should_have_attached_file :avatar
|
53
|
+
end
|
54
|
+
|
55
|
+
# will_paginate
|
56
|
+
class PostTest < Test::Unit::TestCase
|
57
|
+
should_have_per_page 10
|
58
|
+
end
|
59
|
+
|
60
|
+
# acts_as_solr
|
61
|
+
class ProductTest < Test::Unit::TestCase
|
62
|
+
should_act_as_solr :name, :price
|
63
|
+
end</code></pre>
|
64
|
+
|
65
|
+
h2. The source
|
66
|
+
|
67
|
+
The source is available from "GitHub":http://github.com/seanhussey/woulda/tree/master.
|
68
|
+
|
69
|
+
Clone it: <pre>git clone git://github.com/seanhussey/woulda.git</pre>
|
70
|
+
|
71
|
+
h2. Credit
|
72
|
+
|
73
|
+
Written by "Sean Hussey":mailto:sean@seanhussey.com and "Josh Nichols":http://technicalpickles.com
|
74
|
+
|
75
|
+
Copyright 2008 Sean Hussey and Josh Nichols.
|
data/Rakefile
CHANGED
@@ -5,19 +5,19 @@ require 'rake/gempackagetask'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = "woulda"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
s.summary = "woulda is a home for shoulda macros that don't belong in the main shoulda library"
|
10
10
|
s.homepage = "http://github.com/seanhussey/woulda"
|
11
11
|
s.rubyforge_project = "woulda"
|
12
12
|
|
13
|
-
s.files = FileList["[A-Z]*", "{shoulda_macros}/**/*"]
|
13
|
+
s.files = FileList["[A-Z]*", "{shoulda_macros}/**/*", "lib/**/*"]
|
14
14
|
|
15
15
|
# s.has_rdoc = true
|
16
16
|
# s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"]
|
17
17
|
# s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc"]
|
18
18
|
|
19
|
-
s.
|
20
|
-
s.email
|
19
|
+
s.authors = ["Sean Hussey", "Josh Nichols"]
|
20
|
+
s.email = ["sean@seanhussey.com", "josh@technicalpickles.com"]
|
21
21
|
|
22
22
|
s.add_dependency "thoughtbot-shoulda", ">= 2.0.0"
|
23
23
|
end
|
@@ -32,4 +32,4 @@ task :gemspec do
|
|
32
32
|
File.open("#{spec.name}.gemspec", 'w') do |f|
|
33
33
|
f.write spec.to_ruby
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsFerret
|
3
|
+
module Macros
|
4
|
+
# should_act_as_ferret :any, :fields, :i_may, :have, :specified
|
5
|
+
# Original source: http://www.soyunperdedor.com/node/34
|
6
|
+
def should_act_as_ferret(*fields)
|
7
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
8
|
+
|
9
|
+
should "include ActsAsFerret methods" do
|
10
|
+
assert klass.extended_by.include?(ActsAsFerret::ClassMethods)
|
11
|
+
assert klass.include?(ActsAsFerret::InstanceMethods)
|
12
|
+
assert klass.include?(ActsAsFerret::MoreLikeThis::InstanceMethods)
|
13
|
+
assert klass.include?(ActsAsFerret::ResultAttributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
fields.each do |f|
|
17
|
+
should "create an index for field named #{f}" do
|
18
|
+
assert klass.aaf_configuration[:fields].include?(f)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsList
|
3
|
+
module Macros
|
4
|
+
# Original source: http://www.soyunperdedor.com/node/34
|
5
|
+
def should_act_as_list
|
6
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
7
|
+
|
8
|
+
context "To support acts_as_list" do
|
9
|
+
should_have_db_column('position', :type => :integer)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "include ActsAsList methods" do
|
13
|
+
assert klass.include?(ActiveRecord::Acts::List::InstanceMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
should_have_instance_methods :acts_as_list_class, :position_column, :scope_condition
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsParanoid
|
3
|
+
module Macros
|
4
|
+
def should_act_as_paranoid
|
5
|
+
klass = model_class
|
6
|
+
should_have_db_column :deleted_at
|
7
|
+
|
8
|
+
context "A #{klass.name}" do
|
9
|
+
should "be paranoid (it will not be deleted from the database)" do
|
10
|
+
assert klass.paranoid?
|
11
|
+
assert klass.included_modules.include?(Caboose::Acts::Paranoid)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "not have a value for deleted_at" do
|
15
|
+
assert object = klass.find(:first)
|
16
|
+
assert_nil object.deleted_at
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when destroyed" do
|
20
|
+
setup do
|
21
|
+
assert object = klass.find(:first), "This context requires there to be an existing #{klass}"
|
22
|
+
@deleted_id = object.id
|
23
|
+
object.destroy
|
24
|
+
end
|
25
|
+
|
26
|
+
should "not be found" do
|
27
|
+
assert_raise(ActiveRecord::RecordNotFound) { klass.find(@deleted_id) }
|
28
|
+
end
|
29
|
+
|
30
|
+
should "still exist in the database" do
|
31
|
+
deleted_object = klass.find_with_deleted(@deleted_id)
|
32
|
+
assert_not_nil deleted_object.deleted_at
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsParanoid
|
3
|
+
module Macros
|
4
|
+
def self.should_act_as_solr(*included_associations)
|
5
|
+
klass = model_class
|
6
|
+
|
7
|
+
context "A #{klass.name}" do
|
8
|
+
should "include the acts_as_solr modules" do
|
9
|
+
assert klass.included_modules.include?(ActsAsSolr::ParserMethods)
|
10
|
+
assert klass.included_modules.include?(ActsAsSolr::CommonMethods)
|
11
|
+
assert klass.included_modules.include?(ActsAsSolr::InstanceMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be extended by the acts_as_solr modules" do
|
15
|
+
assert klass.extended_by.include?(ActsAsSolr::ClassMethods)
|
16
|
+
assert klass.extended_by.include?(ActsAsSolr::ParserMethods)
|
17
|
+
assert klass.extended_by.include?(ActsAsSolr::CommonMethods)
|
18
|
+
assert klass.extended_by.include?(ActsAsSolr::PaginationExtension)
|
19
|
+
end
|
20
|
+
|
21
|
+
included_associations.each do |association|
|
22
|
+
should "include the #{association.to_s} association in solr indexing" do
|
23
|
+
klass.configuration[:include].include?(association)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsTaggableOnSteroids
|
3
|
+
module Macros
|
4
|
+
# Original source: http://www.soyunperdedor.com/node/34
|
5
|
+
def should_act_as_taggable_on_steroids
|
6
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
7
|
+
|
8
|
+
should "include ActsAsTaggableOnSteroids methods" do
|
9
|
+
assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::ClassMethods)
|
10
|
+
assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::SingletonMethods)
|
11
|
+
assert klass.include?(ActiveRecord::Acts::Taggable::InstanceMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
should_have_many :taggings, :tags
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Woulda
|
2
|
+
module AttachmentFu
|
3
|
+
module Macros
|
4
|
+
def should_have_attachment(options = {})
|
5
|
+
klass = model_class
|
6
|
+
|
7
|
+
should_have_db_columns :size, :content_type, :filename
|
8
|
+
if options[:content_type] == :image
|
9
|
+
should_have_db_columns :height, :width
|
10
|
+
end
|
11
|
+
|
12
|
+
should "define AttachmentFu class methods" do
|
13
|
+
# breakpoint
|
14
|
+
class_modules = (class << klass; included_modules; end)
|
15
|
+
assert class_modules.include?(Technoweenie::AttachmentFu::ClassMethods),
|
16
|
+
"#{klass} doesn't define AttachmentFu class methods"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "define AttachmentFu instance methods" do
|
20
|
+
instance_modules = klass.included_modules
|
21
|
+
assert instance_modules.include?(Technoweenie::AttachmentFu::InstanceMethods),
|
22
|
+
"#{klass} doesn't define AttachmentFu instance methods"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Woulda
|
2
|
+
module EnumerationsMixin
|
3
|
+
module Macros
|
4
|
+
def should_act_as_enumerated(options = {})
|
5
|
+
klass = model_class
|
6
|
+
|
7
|
+
should_have_db_columns :name
|
8
|
+
|
9
|
+
should "define Enumerated macro methods" do
|
10
|
+
class_modules = (class << klass; included_modules; end)
|
11
|
+
assert class_modules.include?(ActiveRecord::Acts::Enumerated::MacroMethods), "#{klass} doesn't define Enumerated macro methods"
|
12
|
+
end
|
13
|
+
|
14
|
+
should "define Enumerated class methods" do
|
15
|
+
class_modules = (class << klass; included_modules; end)
|
16
|
+
assert class_modules.include?(ActiveRecord::Acts::Enumerated::ClassMethods), "#{klass} doesn't define Enumerated class methods"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "define Enumerated instance methods" do
|
20
|
+
instance_modules = klass.included_modules
|
21
|
+
assert instance_modules.include?(ActiveRecord::Acts::Enumerated::InstanceMethods), "#{klass} doesn't define Enumerated instance methods"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Woulda
|
2
|
+
module Paperclip
|
3
|
+
module Macros
|
4
|
+
# Original source: http://giantrobots.thoughtbot.com/2008/6/3/testing-paperclip-with-shoulda
|
5
|
+
def should_have_attached_file(attachment)
|
6
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
7
|
+
|
8
|
+
context "To support a paperclip attachment named #{attachment}, #{klass}" do
|
9
|
+
should_have_db_column("#{attachment}_file_name", :type => :string)
|
10
|
+
should_have_db_column("#{attachment}_content_type", :type => :string)
|
11
|
+
should_have_db_column("#{attachment}_file_size", :type => :integer)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have a paperclip attachment named ##{attachment}" do
|
15
|
+
assert klass.new.respond_to?(attachment.to_sym),
|
16
|
+
"@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
|
17
|
+
assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Woulda
|
2
|
+
module WillPaginate
|
3
|
+
module Macros
|
4
|
+
def should_have_per_page(count)
|
5
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
6
|
+
context "#{klass}" do
|
7
|
+
should "respond to per_page" do
|
8
|
+
assert klass.respond_to?(:per_page), "#{klass} does not respond to :per_page"
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have #{count} per page" do
|
12
|
+
assert_equal count, klass.per_page
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/woulda.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'woulda/acts_as_ferret' if defined? ActsAsFerret
|
2
|
+
require 'woulda/acts_as_list' if defined? ActiveRecord::Acts::List
|
3
|
+
require 'woulda/acts_as_paranoid' if defined? Caboose::Acts::Paranoid
|
4
|
+
require 'woulda/acts_as_taggable_on_steroids' if defined? ActiveRecord::Acts::Taggable
|
5
|
+
require 'woulda/attachment_fu' if defined? Technoweenie::AttachmentFu
|
6
|
+
require 'woulda/enumerations_mixin' if defined? ActiveRecord::Acts::Enumerated
|
7
|
+
require 'woulda/paperclip' if defined? Paperclip
|
8
|
+
require 'woulda/will_paginate' if defined? WillPaginate
|
9
|
+
require 'woulda/acts_as_solr' if defined? ActsAsSolr
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'woulda'
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seanhussey-woulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Hussey
|
8
|
+
- Josh Nichols
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2008-09-
|
13
|
+
date: 2008-09-30 00:00:00 -07:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +23,9 @@ dependencies:
|
|
22
23
|
version: 2.0.0
|
23
24
|
version:
|
24
25
|
description:
|
25
|
-
email:
|
26
|
+
email:
|
27
|
+
- sean@seanhussey.com
|
28
|
+
- josh@technicalpickles.com
|
26
29
|
executables: []
|
27
30
|
|
28
31
|
extensions: []
|
@@ -32,8 +35,37 @@ extra_rdoc_files: []
|
|
32
35
|
files:
|
33
36
|
- LICENSE
|
34
37
|
- Rakefile
|
35
|
-
- README
|
36
|
-
- shoulda_macros/
|
38
|
+
- README.textile
|
39
|
+
- shoulda_macros/woulda_macros.rb
|
40
|
+
- lib/woulda
|
41
|
+
- lib/woulda/acts_as_ferret
|
42
|
+
- lib/woulda/acts_as_ferret/macros.rb
|
43
|
+
- lib/woulda/acts_as_ferret.rb
|
44
|
+
- lib/woulda/acts_as_list
|
45
|
+
- lib/woulda/acts_as_list/macros.rb
|
46
|
+
- lib/woulda/acts_as_list.rb
|
47
|
+
- lib/woulda/acts_as_paranoid
|
48
|
+
- lib/woulda/acts_as_paranoid/macros.rb
|
49
|
+
- lib/woulda/acts_as_paranoid.rb
|
50
|
+
- lib/woulda/acts_as_solr
|
51
|
+
- lib/woulda/acts_as_solr/macros.rb
|
52
|
+
- lib/woulda/acts_as_solr.rb
|
53
|
+
- lib/woulda/acts_as_taggable_on_steroids
|
54
|
+
- lib/woulda/acts_as_taggable_on_steroids/macros.rb
|
55
|
+
- lib/woulda/acts_as_taggable_on_steroids.rb
|
56
|
+
- lib/woulda/attachment_fu
|
57
|
+
- lib/woulda/attachment_fu/macros.rb
|
58
|
+
- lib/woulda/attachment_fu.rb
|
59
|
+
- lib/woulda/enumerations_mixin
|
60
|
+
- lib/woulda/enumerations_mixin/macros.rb
|
61
|
+
- lib/woulda/enumerations_mixin.rb
|
62
|
+
- lib/woulda/paperclip
|
63
|
+
- lib/woulda/paperclip/macros.rb
|
64
|
+
- lib/woulda/paperclip.rb
|
65
|
+
- lib/woulda/will_paginate
|
66
|
+
- lib/woulda/will_paginate/macros.rb
|
67
|
+
- lib/woulda/will_paginate.rb
|
68
|
+
- lib/woulda.rb
|
37
69
|
has_rdoc: false
|
38
70
|
homepage: http://github.com/seanhussey/woulda
|
39
71
|
post_install_message:
|
data/README
DELETED
File without changes
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class Test::Unit::TestCase
|
2
|
-
def self.should_act_as_paranoid
|
3
|
-
klass = model_class
|
4
|
-
|
5
|
-
context "A #{klass.name}" do
|
6
|
-
should "be paranoid (it will not be deleted from the database)" do
|
7
|
-
klass.paranoid?
|
8
|
-
end
|
9
|
-
|
10
|
-
should "not have a value for deleted_at" do
|
11
|
-
assert object = klass.find(:first)
|
12
|
-
assert_nil object.deleted_at
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when destroyed" do
|
16
|
-
setup do
|
17
|
-
assert object = klass.find(:first)
|
18
|
-
@deleted_id = object.id
|
19
|
-
object.destroy
|
20
|
-
end
|
21
|
-
|
22
|
-
should "not be found" do
|
23
|
-
assert_raise(ActiveRecord::RecordNotFound) { klass.find(@deleted_id) }
|
24
|
-
end
|
25
|
-
|
26
|
-
should "still exist in the database" do
|
27
|
-
deleted_object = klass.find_with_deleted(@deleted_id)
|
28
|
-
assert_not_nil deleted_object.deleted_at
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|