riot-mongo_mapper 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,8 +1,5 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'mg'
4
-
5
- MG.new(File.join(File.dirname(__FILE__),"riot-mongo_mapper.gemspec"))
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
6
3
 
7
4
  require 'rake/testtask'
8
5
  Rake::TestTask.new(:test) do |test|
@@ -10,27 +7,3 @@ Rake::TestTask.new(:test) do |test|
10
7
  test.pattern = 'test/**/*_test.rb'
11
8
  test.verbose = true
12
9
  end
13
-
14
- begin
15
- require 'rcov/rcovtask'
16
- Rcov::RcovTask.new do |test|
17
- test.libs << 'test'
18
- test.pattern = 'test/**/*_test.rb'
19
- test.verbose = true
20
- end
21
- rescue LoadError
22
- task :rcov do
23
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
24
- end
25
- end
26
-
27
- task :default => :test
28
-
29
- begin
30
- require 'yard'
31
- YARD::Rake::YardocTask.new
32
- rescue LoadError
33
- task :yardoc do
34
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
35
- end
36
- end
@@ -4,14 +4,20 @@ module RiotMongoMapper
4
4
 
5
5
  def evaluate(model, *association_macro_info)
6
6
  association_name, key_name, options = association_macro_info
7
- association = model.associations[key_name.to_s]
7
+ association = model.associations[key_name.to_sym]
8
+ association_class = case association_name
9
+ when :many
10
+ MongoMapper::Plugins::Associations::ManyAssociation
11
+ when :one
12
+ MongoMapper::Plugins::Associations::OneAssociation
13
+ end
8
14
  if association.nil?
9
15
  fail("expected #{model} to have association #{association}")
10
16
  else
11
- association_valid = association.type == association_name.to_sym
17
+ association_valid = association.class == association_class
12
18
  options_valid = options ? options.all? { |field,value| association.options[field] == value } : true
13
19
  options_valid && association_valid ? pass("#{model} has association '#{association_name}' on '#{key_name}' with options #{options.inspect}") :
14
- fail("expected #{model} to have association #{association_name} with options #{options.inspect} on key #{key_name}")
20
+ fail("expected #{model} to have association #{association_name} with options #{options.inspect} on key #{key_name}")
15
21
  end
16
22
  end
17
23
  end
@@ -4,7 +4,7 @@ module RiotMongoMapper
4
4
 
5
5
  def evaluate(model, *key_macro_info)
6
6
  key_name, key_type, options = key_macro_info
7
- key = model.keys[key_name.to_sym]
7
+ key = model.keys[key_name.to_s]
8
8
  if key.nil?
9
9
  fail("expected #{model} to have field #{key_name}")
10
10
  else
@@ -3,20 +3,39 @@ module RiotMongoMapper
3
3
  register :has_validation
4
4
 
5
5
  def evaluate(model, *validation_macro_info)
6
- validation_type, validation_name, options = validation_macro_info
7
- validation = model.send(:all_validations).detect do |valid|
8
- valid.key =~ %r{#{validation_type.to_s.camelize}} and valid.attribute == validation_name
6
+ validation_type, validation_field, options = validation_macro_info
7
+ type = validation_type.to_s
8
+
9
+ %w{validates_ _of}.each { |part| type.gsub!(%r{#{part}},'') }
10
+
11
+ validation = model._validators[validation_field].detect do |valid|
12
+ valid.class.name =~ /#{type.camelize}/
9
13
  end
14
+
10
15
  options ||= {}
16
+
11
17
  case
12
- when validation_name.nil? || validation_type.nil?
13
- fail("validation name, type and potential options must be specified with this assertion macro")
14
- when validation.nil?
15
- fail("expected #{model} to have validation on #{validation_name} of type #{validation_type}")
16
- else
17
- options_valid = options.all? { |key,value| validation.send(key) == value }
18
- options_valid ? pass("#{model} has '#{validation_type}' validation '#{validation_name}' with options #{options.inspect}") :
19
- fail("expected #{model} to have validations on #{validation_name} with options #{options.inspect} of type #{validation_type}")
18
+ when validation_field.nil? || validation_type.nil?
19
+ fail("validation field, type and potential options must be specified with this assertion macro")
20
+
21
+ when validation.nil?
22
+ fail("expected #{model} to have validation on #{validation_field} of type #{validation_type}")
23
+
24
+ when (validation.class.name =~ %r{Length} and options[:within])
25
+ range = options[:within].to_a
26
+ if (validation.options[:minimum] == range.first) and (validation.options[:maximum] == range.last)
27
+ pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
28
+ else
29
+ fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
30
+ end
31
+
32
+ else
33
+ options_valid = options.all? { |key,value| validation.options[key] == value }
34
+ if options_valid
35
+ pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
36
+ else
37
+ fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
38
+ end
20
39
  end
21
40
  end
22
41
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riot-mongo_mapper"
3
- s.version = "0.0.3"
3
+ s.version = "0.1.0"
4
4
  s.required_rubygems_version = ">= 1.3.6"
5
5
  s.authors = ["Arthur Chiu"]
6
6
  s.date = Time.now.strftime("%Y-%m-%d")
@@ -12,9 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.rdoc_options = ["--charset=UTF-8"]
13
13
  s.require_paths = ["lib"]
14
14
  s.summary = %q{Riot assertions for MongoMapper}
15
- s.add_development_dependency(%q<riot>, [">= 0"])
16
- s.add_development_dependency(%q<yard>, [">= 0"])
17
- s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.8.2"])
18
- s.add_runtime_dependency(%q<riot>, [">= 0.11.2"])
15
+ s.add_dependency 'mongo_mapper', '~>0.9.0'
16
+ s.add_dependency 'riot', '~>0.12.3'
19
17
  end
20
18
 
@@ -1,6 +1,8 @@
1
1
  module Plugins
2
2
  module Test
3
+ extend ActiveSupport::Concern
3
4
  end
4
5
  module Faux
6
+ extend ActiveSupport::Concern
5
7
  end
6
8
  end
@@ -1,7 +1,8 @@
1
- require File.join(File.dirname(__FILE__),'teststrap')
1
+ require File.expand_path('../teststrap', __FILE__)
2
2
 
3
3
  context "has_association macro" do
4
- setup{ @assertion = RiotMongoMapper::HasAssociationAssertion.new }
4
+ helper(:macro) { RiotMongoMapper::HasAssociationAssertion.new }
5
+
5
6
  setup do
6
7
  mock_model do
7
8
  many :persons
@@ -9,24 +10,24 @@ context "has_association macro" do
9
10
  end
10
11
  end
11
12
 
12
- asserts "passes when has association" do
13
- @assertion.evaluate(topic, :many, :persons).first
13
+ asserts "passes when has association" do
14
+ macro.evaluate(topic, :many, :persons).first
14
15
  end.equals(:pass)
15
16
 
16
- asserts "fails when has association" do
17
- @assertion.evaluate(topic, :many, :dogs).first
17
+ asserts "fails when has association" do
18
+ macro.evaluate(topic, :many, :dogs).first
18
19
  end.equals(:fail)
19
20
 
20
- asserts "passes when association options is specified" do
21
- @assertion.evaluate(topic, :many, :categories, :in => :category_ids, :class_name => 'Tags').first
21
+ asserts "passes when association options is specified" do
22
+ macro.evaluate(topic, :many, :categories, :in => :category_ids, :class_name => 'Tags').first
22
23
  end.equals(:pass)
23
24
 
24
- asserts "fails when the options don't match" do
25
- @assertion.evaluate(topic, :many, :categories, :foreign_id => 'wtf').first
25
+ asserts "fails when the options don't match" do
26
+ macro.evaluate(topic, :many, :categories, :foreign_id => 'wtf').first
26
27
  end.equals(:fail)
27
28
 
28
- asserts "returns a message" do
29
- @assertion.evaluate(topic, :many, :persons).last
29
+ asserts "returns a message" do
30
+ macro.evaluate(topic, :many, :persons).last
30
31
  end.matches %r{has association 'many' on 'persons' with options}
31
32
 
32
- end
33
+ end
@@ -1,7 +1,8 @@
1
- require File.join(File.dirname(__FILE__),'teststrap')
1
+ require File.expand_path('../teststrap', __FILE__)
2
2
 
3
3
  context "has_key macro" do
4
- setup { @assertion = RiotMongoMapper::HasKeyAssertion.new }
4
+ helper(:macro) { RiotMongoMapper::HasKeyAssertion.new }
5
+
5
6
  setup do
6
7
  mock_model do
7
8
  key :name, String
@@ -11,23 +12,23 @@ context "has_key macro" do
11
12
  end
12
13
 
13
14
  asserts "passes when the key is specified" do
14
- @assertion.evaluate(topic, :name, String).first
15
+ macro.evaluate(topic, :name, String).first
15
16
  end.equals(:pass)
16
17
 
17
- asserts "fails when the key doesn't match" do
18
- @assertion.evaluate(topic, :name, Array).first
18
+ asserts "fails when the key doesn't match" do
19
+ macro.evaluate(topic, :name, Array).first
19
20
  end.equals(:fail)
20
21
 
21
- asserts "passes when options are specified" do
22
- @assertion.evaluate(topic, :age, Integer, :required => true, :default => 18).first
22
+ asserts "passes when options are specified" do
23
+ macro.evaluate(topic, :age, Integer, :required => true, :default => 18).first
23
24
  end.equals(:pass)
24
25
 
25
- asserts "fails when the options specifed don't match" do
26
- @assertion.evaluate(topic, :foo, Boolean, :default => true).first
26
+ asserts "fails when the options specifed don't match" do
27
+ macro.evaluate(topic, :foo, Boolean, :default => true).first
27
28
  end.equals(:fail)
28
29
 
29
- asserts "returns a message" do
30
- @assertion.evaluate(topic, :name, String).last
30
+ asserts "returns a message" do
31
+ macro.evaluate(topic, :name, String).last
31
32
  end.matches %r{has key 'name' with options}
32
33
 
33
34
 
@@ -1,23 +1,24 @@
1
- require File.join(File.dirname(__FILE__),'teststrap')
2
- require File.join(File.dirname(__FILE__), 'fixtures', 'test')
1
+ require File.expand_path('../teststrap', __FILE__)
2
+ require File.expand_path('../fixtures/test', __FILE__)
3
3
 
4
4
  context "has_plugin macro" do
5
- setup{ @assertion = RiotMongoMapper::HasPluginAssertion.new }
5
+ helper(:macro) { RiotMongoMapper::HasPluginAssertion.new }
6
+
6
7
  setup do
7
8
  mock_model do
8
9
  plugin Plugins::Test
9
10
  end
10
11
  end
11
12
 
12
- asserts "passes when has plugin" do
13
- @assertion.evaluate(topic, Plugins::Test).first
13
+ asserts "passes when has plugin" do
14
+ macro.evaluate(topic, Plugins::Test).first
14
15
  end.equals(:pass)
15
16
 
16
- asserts "fails when it doesn't have plugin" do
17
- @assertion.evaluate(topic, Plugins::Faux).first
17
+ asserts "fails when it doesn't have plugin" do
18
+ macro.evaluate(topic, Plugins::Faux).first
18
19
  end.equals(:fail)
19
20
 
20
- asserts "returns a message" do
21
- @assertion.evaluate(topic, Plugins::Test).last
22
- end.matches %r{has plugin Plugins::Test}
23
- end
21
+ asserts "returns a message" do
22
+ macro.evaluate(topic, Plugins::Test).last
23
+ end.matches %r{has plugin Plugins::Test}
24
+ end
@@ -1,7 +1,9 @@
1
- require File.join(File.dirname(__FILE__),'teststrap')
1
+ require File.expand_path('../teststrap', __FILE__)
2
2
 
3
3
  context "has_validation macro" do
4
- setup { @assertion = RiotMongoMapper::HasValidationAssertion.new }
4
+
5
+ helper(:macro) { RiotMongoMapper::HasValidationAssertion.new }
6
+
5
7
  setup do
6
8
  mock_model do
7
9
  key :name, String
@@ -15,30 +17,30 @@ context "has_validation macro" do
15
17
  end
16
18
 
17
19
  asserts "passes when the validation is specified" do
18
- @assertion.evaluate(topic, :validates_presence_of, :name).first
20
+ macro.evaluate(topic, :validates_presence_of, :name).first
19
21
  end.equals(:pass)
20
22
 
21
23
  asserts "passes when the validation is specified" do
22
- @assertion.evaluate(topic, :validates_presence_of, :surname).first
24
+ macro.evaluate(topic, :validates_presence_of, :surname).first
23
25
  end.equals(:pass)
24
26
 
25
27
  asserts "returns useful message" do
26
- @assertion.evaluate(topic, :validates_presence_of, :name).last
28
+ macro.evaluate(topic, :validates_presence_of, :name).last
27
29
  end.matches(/has 'validates_presence_of' validation 'name'/)
28
30
 
29
31
  asserts "passes when the validation options is specified" do
30
- @assertion.evaluate(topic, :validates_length_of, :surname, :within => 4..40).first
32
+ macro.evaluate(topic, :validates_length_of, :surname, :within => 4..40).first
31
33
  end.equals(:pass)
32
34
 
33
35
  asserts "passes when the validation options is specified and doesn't match" do
34
- @assertion.evaluate(topic, :validates_length_of, :surname, :within => 3..30).first
36
+ macro.evaluate(topic, :validates_length_of, :surname, :within => 3..30).first
35
37
  end.equals(:fail)
36
38
 
37
39
  asserts "fails when invalid field options are specified" do
38
- @assertion.evaluate(topic, :validates_length_of, :name, :type => Date).first
40
+ macro.evaluate(topic, :validates_length_of, :name, :type => Date).first
39
41
  end.equals(:fail)
40
42
 
41
43
  asserts "passes when another validation is specified" do
42
- @assertion.evaluate(topic, :validates_uniqueness_of, :rad).first
44
+ macro.evaluate(topic, :validates_uniqueness_of, :rad).first
43
45
  end.equals(:pass)
44
46
  end
@@ -1,8 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'riot'
3
3
  require 'mongo_mapper'
4
- require File.join(File.dirname(__FILE__),'..','lib','riot-mongo_mapper')
5
-
4
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/riot-mongo_mapper.rb')
6
5
 
7
6
  class Riot::Situation
8
7
  def mock_model(&block)
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riot-mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.1.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Arthur Chiu
@@ -15,69 +10,31 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-07-23 00:00:00 -07:00
13
+ date: 2011-04-16 00:00:00 -07:00
19
14
  default_executable:
20
15
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: riot
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: yard
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
47
- type: :development
48
- version_requirements: *id002
49
16
  - !ruby/object:Gem::Dependency
50
17
  name: mongo_mapper
51
18
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
19
+ requirement: &id001 !ruby/object:Gem::Requirement
53
20
  none: false
54
21
  requirements:
55
- - - ">="
22
+ - - ~>
56
23
  - !ruby/object:Gem::Version
57
- hash: 59
58
- segments:
59
- - 0
60
- - 8
61
- - 2
62
- version: 0.8.2
24
+ version: 0.9.0
63
25
  type: :runtime
64
- version_requirements: *id003
26
+ version_requirements: *id001
65
27
  - !ruby/object:Gem::Dependency
66
28
  name: riot
67
29
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
69
31
  none: false
70
32
  requirements:
71
- - - ">="
33
+ - - ~>
72
34
  - !ruby/object:Gem::Version
73
- hash: 55
74
- segments:
75
- - 0
76
- - 11
77
- - 2
78
- version: 0.11.2
35
+ version: 0.12.3
79
36
  type: :runtime
80
- version_requirements: *id004
37
+ version_requirements: *id002
81
38
  description: A collection of assertion macros for testing MongoMapper with Riot
82
39
  email: mr.arthur.chiu@gmail.com
83
40
  executables: []
@@ -116,25 +73,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
73
  requirements:
117
74
  - - ">="
118
75
  - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
76
  version: "0"
123
77
  required_rubygems_version: !ruby/object:Gem::Requirement
124
78
  none: false
125
79
  requirements:
126
80
  - - ">="
127
81
  - !ruby/object:Gem::Version
128
- hash: 23
129
- segments:
130
- - 1
131
- - 3
132
- - 6
133
82
  version: 1.3.6
134
83
  requirements: []
135
84
 
136
85
  rubyforge_project:
137
- rubygems_version: 1.3.7
86
+ rubygems_version: 1.6.1
138
87
  signing_key:
139
88
  specification_version: 3
140
89
  summary: Riot assertions for MongoMapper