seanhussey-woulda 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -1
- data/lib/woulda.rb +12 -10
- data/lib/woulda/acts_as_ferret.rb +1 -1
- data/lib/woulda/acts_as_list.rb +1 -1
- data/lib/woulda/acts_as_paranoid.rb +1 -1
- data/lib/woulda/acts_as_solr.rb +1 -1
- data/lib/woulda/acts_as_solr/macros.rb +34 -15
- data/lib/woulda/acts_as_state_machine.rb +1 -1
- data/lib/woulda/acts_as_state_machine/macros.rb +7 -5
- data/lib/woulda/acts_as_taggable_on_steroids.rb +1 -1
- data/lib/woulda/attachment_fu.rb +1 -1
- data/lib/woulda/enumerations_mixin.rb +1 -1
- data/lib/woulda/paperclip.rb +2 -2
- data/lib/woulda/paperclip/macros.rb +1 -1
- data/lib/woulda/should_raise.rb +6 -0
- data/lib/woulda/should_raise/macros.rb +102 -0
- metadata +5 -2
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ 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.5"
|
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"
|
@@ -33,3 +33,11 @@ task :gemspec do
|
|
33
33
|
f.write spec.to_ruby
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
desc "Run all tests"
|
38
|
+
Rake::TestTask.new(:test) do |t|
|
39
|
+
t.pattern = 'test/**/*_test.rb'
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
data/lib/woulda.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
woulda_dir = File.expand_path(File.dirname(__FILE__)) + '/woulda'
|
2
|
+
require "#{woulda_dir}/should_raise"
|
3
|
+
require "#{woulda_dir}/acts_as_ferret" if defined? ActsAsFerret
|
4
|
+
require "#{woulda_dir}/acts_as_list" if defined? ActiveRecord::Acts::List
|
5
|
+
require "#{woulda_dir}/acts_as_paranoid" if defined? Caboose::Acts::Paranoid
|
6
|
+
require "#{woulda_dir}/acts_as_taggable_on_steroids" if defined? ActiveRecord::Acts::Taggable
|
7
|
+
require "#{woulda_dir}/attachment_fu" if defined? Technoweenie::AttachmentFu
|
8
|
+
require "#{woulda_dir}/enumerations_mixin" if defined? ActiveRecord::Acts::Enumerated
|
9
|
+
require "#{woulda_dir}/paperclip" if defined? Paperclip
|
10
|
+
require "#{woulda_dir}/will_paginate" if defined? WillPaginate
|
11
|
+
require "#{woulda_dir}/acts_as_solr" if defined? ActsAsSolr
|
12
|
+
require "#{woulda_dir}/acts_as_state_machine" if defined? ScottBarron::Acts::StateMachine
|
data/lib/woulda/acts_as_list.rb
CHANGED
data/lib/woulda/acts_as_solr.rb
CHANGED
@@ -1,24 +1,43 @@
|
|
1
1
|
module Woulda
|
2
2
|
module ActsAsSolr
|
3
3
|
module Macros
|
4
|
-
def
|
4
|
+
def should_act_as_solr(opts={})
|
5
5
|
klass = model_class
|
6
|
+
|
7
|
+
associations = get_options!([opts], :associations)
|
8
|
+
|
9
|
+
associations ||= []
|
6
10
|
|
7
11
|
context "A #{klass.name}" do
|
8
|
-
should "include the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
# should "include the ActsAsSolr::ParserMethods module" do
|
13
|
+
# assert klass.included_modules.include?(ActsAsSolr::ParserMethods)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# should "include the ActsAsSolr::CommonMethods module" do
|
17
|
+
# assert klass.included_modules.include?(ActsAsSolr::CommonMethods)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# should "include the ActsAsSolr::InstanceMethods module" do
|
21
|
+
# assert klass.included_modules.include?(ActsAsSolr::InstanceMethods)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# should "be extended by the ActsAsSolr::ClassMethods module" do
|
25
|
+
# assert klass.extended_by.include?(ActsAsSolr::ClassMethods)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# should "be extended by the ActsAsSolr::ParserMethods module" do
|
29
|
+
# assert klass.extended_by.include?(ActsAsSolr::ParserMethods)
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# should "be extended by the ActsAsSolr::CommonMethods module" do
|
33
|
+
# assert klass.extended_by.include?(ActsAsSolr::CommonMethods)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# should "be extended by the ActsAsSolr::PaginationExtension module" do
|
37
|
+
# assert klass.extended_by.include?(ActsAsSolr::PaginationExtension)
|
38
|
+
# end
|
20
39
|
|
21
|
-
|
40
|
+
associations.each do |association|
|
22
41
|
should "include the #{association.to_s} association in solr indexing" do
|
23
42
|
klass.configuration[:include].include?(association)
|
24
43
|
end
|
@@ -27,4 +46,4 @@ module Woulda
|
|
27
46
|
end
|
28
47
|
end
|
29
48
|
end
|
30
|
-
end
|
49
|
+
end
|
@@ -69,12 +69,14 @@ module Woulda
|
|
69
69
|
assert klass.transition_table.has_key?(event), "#{klass} does not define event #{event}"
|
70
70
|
end
|
71
71
|
|
72
|
-
to
|
73
|
-
from = transition[:from]
|
72
|
+
to = transition[:to]
|
73
|
+
from = transition[:from].is_a?(Symbol) ? [transition[:from]] : transition[:from]
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
from.each do |from_state|
|
76
|
+
should "transition to #{to} from #{from_state} on event #{event}" do
|
77
|
+
assert_not_nil klass.transition_table[event].detect { |t| t.to == to && t.from == from_state }, "#{event} does not transition to #{to} from #{from_state}"
|
78
|
+
end
|
79
|
+
end
|
78
80
|
|
79
81
|
end
|
80
82
|
end
|
data/lib/woulda/attachment_fu.rb
CHANGED
data/lib/woulda/paperclip.rb
CHANGED
@@ -14,7 +14,7 @@ module Woulda
|
|
14
14
|
should "have a paperclip attachment named ##{attachment}" do
|
15
15
|
assert klass.new.respond_to?(attachment.to_sym),
|
16
16
|
"@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
|
17
|
-
assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
|
17
|
+
assert_equal ::Paperclip::Attachment, klass.new.send(attachment.to_sym).class
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# Copyright (c) 2008 Mathieu Martin
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
# - nest contexts/should differently so the message verifications don't clobber each other.
|
24
|
+
# Put exactly same message in last few tests for an example.
|
25
|
+
|
26
|
+
module Woulda
|
27
|
+
module ShouldRaise
|
28
|
+
module Macros
|
29
|
+
# Make sure a block raises an exception.
|
30
|
+
# Call with optional arguments :instance_of/:kind_of and :message
|
31
|
+
# If :instance_of or :kind_of is specified, assert on the given type.
|
32
|
+
# Otherwise only assert that an exception is raised.
|
33
|
+
# Note: The shorthand should_raise(LoadError) is equivalent to should_raise(:instance_of => LoadError)
|
34
|
+
# If :message is specified, will assert that exception.message =~ :message.
|
35
|
+
#
|
36
|
+
# Examples:
|
37
|
+
# should_raise {a block}
|
38
|
+
# should_raise(LoadError) {a block}
|
39
|
+
# should_raise(:instance_of => LoadError) {a block}
|
40
|
+
# should_raise(:kind_of => LoadError) {a block}
|
41
|
+
# should_raise(:message => "no such file to load") {a block}
|
42
|
+
# should_raise(:message => /load/) {a block}
|
43
|
+
# should_raise(LoadError, :message => /load/) {a block}
|
44
|
+
# should_raise(:kind_of => LoadError, :message => /load/) {a block}
|
45
|
+
# should_raise(:instance_of => LoadError, :message => /load/) {a block}
|
46
|
+
def should_raise(*args, &block)
|
47
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
48
|
+
|
49
|
+
if args.first.is_a?(Class)
|
50
|
+
type = args.first
|
51
|
+
exact = true
|
52
|
+
else
|
53
|
+
type = opts[:instance_of] || opts[:kind_of]
|
54
|
+
exact = !!opts[:instance_of]
|
55
|
+
end
|
56
|
+
message = opts[:message]
|
57
|
+
|
58
|
+
# Make sure we don't have a false sense of security and bork if incorrect options are supplied.
|
59
|
+
[:message, :instance_of, :kind_of].each { |acceptable_arg| opts.delete(acceptable_arg) }
|
60
|
+
raise ArgumentError, "Unknown parameter(s): #{opts.keys.inspect}. Only :message, :instance_of and :kind_of are supported." if opts.size > 0
|
61
|
+
|
62
|
+
context "block #{block.inspect}" do # To avoid dupe test names. Any other ideas?
|
63
|
+
should_string = "raise an exception"
|
64
|
+
should_string += " %s type #{type.inspect}" % (exact ? 'of' : 'descending from') if type
|
65
|
+
|
66
|
+
should should_string do
|
67
|
+
begin
|
68
|
+
yield
|
69
|
+
rescue Exception => ex
|
70
|
+
@raised_exception = ex
|
71
|
+
end
|
72
|
+
if @raised_exception && type
|
73
|
+
if exact
|
74
|
+
assert_instance_of type, @raised_exception
|
75
|
+
else
|
76
|
+
assert_kind_of type, @raised_exception
|
77
|
+
end
|
78
|
+
else
|
79
|
+
assert @raised_exception, "The block was expected to raise an exception, but didn't"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if message
|
85
|
+
context "raising an exception" do
|
86
|
+
setup do
|
87
|
+
begin
|
88
|
+
yield
|
89
|
+
rescue Exception => ex
|
90
|
+
@raised_exception = ex
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
should "contain a message that matches #{message.inspect}" do
|
95
|
+
assert_match message, @raised_exception.message
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Hussey
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-
|
13
|
+
date: 2008-11-01 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -65,6 +65,9 @@ files:
|
|
65
65
|
- lib/woulda/paperclip
|
66
66
|
- lib/woulda/paperclip/macros.rb
|
67
67
|
- lib/woulda/paperclip.rb
|
68
|
+
- lib/woulda/should_raise
|
69
|
+
- lib/woulda/should_raise/macros.rb
|
70
|
+
- lib/woulda/should_raise.rb
|
68
71
|
- lib/woulda/will_paginate
|
69
72
|
- lib/woulda/will_paginate/macros.rb
|
70
73
|
- lib/woulda/will_paginate.rb
|