kelredd-resourceful 0.7.24 → 0.7.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,128 +1,106 @@
1
+ require 'useful/shoulda_macros/test_unit'
1
2
  require 'resourceful/model/base'
2
3
  require 'resourceful/extensions'
3
4
 
4
- module Resourceful
5
- module Shoulda
6
- module TestUnit
7
-
8
- protected
9
-
10
- def should_have_resourceful_attribute(name, opts={})
11
- clean_name = ::Resourceful::Model::Base.cleanup_name(name)
12
- should_have_instance_methods clean_name, "#{clean_name}=", "_#{clean_name}"
13
- should_have_resourceful_typed_attribute(name, opts[:type])
14
- end unless Test::Unit::TestCase.method_defined? :should_have_resourceful_attribute
15
-
16
- def should_have_namespace(ns)
17
- klass = described_type
18
- should "have the namespace '#{ns}' configured" do
19
- assert klass.namespaces.include?(ns), "#{klass} does not have the '#{ns}' namespace"
20
- end
21
- end
22
-
23
- def should_be_findable(index)
24
- should_have_class_methods :find
25
- should_have_instance_methods :save, :destroy
26
- klass = described_type
27
- should "have '#{index}' as a findable index" do
28
- assert_equal index, klass.findable_index, "#{klass} findable index is not '#{index}'"
29
- end
30
- end
31
-
32
- def should_resourcefully_belong_to(name, opts={})
33
- clean_name = ::Resourceful::Model::Base.cleanup_name(name)
34
- should_have_instance_methods clean_name
35
- should_have_resourceful_association_item(name, opts)
36
- end
37
-
38
- def should_resourcefully_have_many(name, opts={})
39
- clean_name = ::Resourceful::Model::Base.cleanup_name(name)
40
- should_have_instance_methods clean_name
41
- should_have_resourceful_association_collection(name, opts)
42
- end
43
-
44
- def should_resourcefully_contain_one(name, opts={})
45
- clean_name = ::Resourceful::Model::Base.cleanup_name(name)
46
- should_have_instance_methods clean_name
47
- should_have_resourceful_association_item(name, opts)
48
- end
49
-
50
- def should_resourcefully_contain_many(name, opts={})
51
- clean_name = ::Resourceful::Model::Base.cleanup_name(name)
52
- should_have_instance_methods clean_name
53
- should_have_resourceful_association_collection(name, opts)
54
- end
55
-
5
+ module Resourceful; end
6
+ module Resourceful::Shoulda; end
56
7
 
8
+ module Resourceful::Shoulda::TestUnit
9
+
10
+ protected
11
+
12
+ def should_have_resourceful_attribute(name, opts={})
13
+ clean_name = ::Resourceful::Model::Base.cleanup_name(name)
14
+ should_have_instance_methods clean_name, "#{clean_name}=", "_#{clean_name}"
15
+ should_have_resourceful_typed_attribute(name, opts[:type])
16
+ end unless Test::Unit::TestCase.method_defined? :should_have_resourceful_attribute
17
+
18
+ def should_have_namespace(ns)
19
+ klass = described_type
20
+ should "have the namespace '#{ns}' configured" do
21
+ assert klass.namespaces.include?(ns), "#{klass} does not have the '#{ns}' namespace"
22
+ end
23
+ end
24
+
25
+ def should_be_findable(index)
26
+ should_have_class_methods :find
27
+ should_have_instance_methods :save, :destroy
28
+ klass = described_type
29
+ should "have '#{index}' as a findable index" do
30
+ assert_equal index, klass.findable_index, "#{klass} findable index is not '#{index}'"
31
+ end
32
+ end
33
+
34
+ def should_resourcefully_belong_to(name, opts={})
35
+ clean_name = ::Resourceful::Model::Base.cleanup_name(name)
36
+ should_have_instance_methods clean_name
37
+ should_have_resourceful_association_item(name, opts)
38
+ end
39
+
40
+ def should_resourcefully_have_many(name, opts={})
41
+ clean_name = ::Resourceful::Model::Base.cleanup_name(name)
42
+ should_have_instance_methods clean_name
43
+ should_have_resourceful_association_collection(name, opts)
44
+ end
45
+
46
+ def should_resourcefully_contain_one(name, opts={})
47
+ clean_name = ::Resourceful::Model::Base.cleanup_name(name)
48
+ should_have_instance_methods clean_name
49
+ should_have_resourceful_association_item(name, opts)
50
+ end
51
+
52
+ def should_resourcefully_contain_many(name, opts={})
53
+ clean_name = ::Resourceful::Model::Base.cleanup_name(name)
54
+ should_have_instance_methods clean_name
55
+ should_have_resourceful_association_collection(name, opts)
56
+ end
57
57
 
58
58
 
59
- private # Helpers ***************************************
60
-
61
- def should_have_resourceful_typed_attribute(name, type)
62
- if type
63
- should "have a #{name} resourceful #{type} value" do
64
- if subject && (val = subject.send(name))
65
- assert_kind_of Resourceful::Model::Base.attribute_type_to_kind(type), val, "#{name} does not have a #{Resourceful::Model::Base.attribute_type_to_kind(type)} kind of value."
66
- end
67
- end
68
- end
69
- end
70
-
71
- def should_have_resourceful_association_item(name, opts)
72
- klass = described_type
73
- should_have_resourceful_association_class(opts)
74
- should "return an item that is a kind of #{opts[:class]}" do
75
- if subject && (val = subject.send(name))
76
- assert_kind_of klass.get_namespaced_klass(opts[:class]), val, "#{name} should be a kind of #{opts[:class]}"
77
- end
59
+
60
+
61
+ private # Helpers ***************************************
62
+
63
+ def should_have_resourceful_typed_attribute(name, type)
64
+ if type
65
+ should "have a #{name} resourceful #{type} value" do
66
+ if subject && (val = subject.send(name))
67
+ assert_kind_of Resourceful::Model::Base.attribute_type_to_kind(type), val, "#{name} does not have a #{Resourceful::Model::Base.attribute_type_to_kind(type)} kind of value."
78
68
  end
79
69
  end
80
-
81
- def should_have_resourceful_association_collection(name, opts)
82
- klass = described_type
83
- should_have_resourceful_association_class(opts)
84
- should "return a collection of items that are a kind of #{opts[:class]}" do
85
- if subject && (val = subject.send(name))
86
- assert_kind_of ::Array, val, "#{name} should be a kind of Array"
87
- if (first_item = val.first)
88
- assert_kind_of klass.get_namespaced_klass(opts[:class]), first_item, "#{name} first item should be a kind of #{opts[:class]}"
89
- end
90
- end
91
- end
70
+ end
71
+ end
72
+
73
+ def should_have_resourceful_association_item(name, opts)
74
+ klass = described_type
75
+ should_have_resourceful_association_class(opts)
76
+ should "return an item that is a kind of #{opts[:class]}" do
77
+ if subject && (val = subject.send(name))
78
+ assert_kind_of klass.get_namespaced_klass(opts[:class]), val, "#{name} should be a kind of #{opts[:class]}"
92
79
  end
93
-
94
- def should_have_resourceful_association_class(opts)
95
- klass = described_type
96
- should "have a #{opts[:class]} class specified that is defined" do
97
- assert opts[:class], "resourceful associations require a :class option"
98
- assert klass.get_namespaced_klass(opts[:class]), "a namespaced #{opts[:class]} is not defined"
80
+ end
81
+ end
82
+
83
+ def should_have_resourceful_association_collection(name, opts)
84
+ klass = described_type
85
+ should_have_resourceful_association_class(opts)
86
+ should "return a collection of items that are a kind of #{opts[:class]}" do
87
+ if subject && (val = subject.send(name))
88
+ assert_kind_of ::Array, val, "#{name} should be a kind of Array"
89
+ if (first_item = val.first)
90
+ assert_kind_of klass.get_namespaced_klass(opts[:class]), first_item, "#{name} first item should be a kind of #{opts[:class]}"
99
91
  end
100
92
  end
101
-
102
- # Ripped from Shoulda::ActiveRecord::Macros
103
- def should_have_instance_methods(*methods)
104
- get_options!(methods)
105
- klass = described_type
106
- methods.each do |method|
107
- should "respond to instance method ##{method}" do
108
- assert_respond_to klass.new, method, "#{klass.name} does not have instance method #{method}"
109
- end
110
- end
111
- end unless Test::Unit::TestCase.method_defined? :should_have_instance_methods
112
-
113
- # Ripped from Shoulda::ActiveRecord::Macros
114
- def should_have_class_methods(*methods)
115
- get_options!(methods)
116
- klass = described_type
117
- methods.each do |method|
118
- should "respond to class method ##{method}" do
119
- assert_respond_to klass, method, "#{klass.name} does not have class method #{method}"
120
- end
121
- end
122
- end unless Test::Unit::TestCase.method_defined? :should_have_class_methods
123
-
124
93
  end
125
94
  end
95
+
96
+ def should_have_resourceful_association_class(opts)
97
+ klass = described_type
98
+ should "have a #{opts[:class]} class specified that is defined" do
99
+ assert opts[:class], "resourceful associations require a :class option"
100
+ assert klass.get_namespaced_klass(opts[:class]), "a namespaced #{opts[:class]} is not defined"
101
+ end
102
+ end
103
+
126
104
  end
127
105
 
128
106
  Test::Unit::TestCase.extend(Resourceful::Shoulda::TestUnit) if defined? Test::Unit::TestCase
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 24
6
+ TINY = 25
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.24
4
+ version: 0.7.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-06 00:00:00 -05:00
12
+ date: 2009-11-24 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,16 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: "0"
64
64
  version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: kelredd-useful
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.2.4
74
+ version:
65
75
  description:
66
76
  email: kelly@kelredd.com
67
77
  executables: []