riot-datamapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in riot-datamapper.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ test.ruby_opts << '-rubygems'
9
+ end
@@ -0,0 +1,40 @@
1
+ module Riot
2
+ module DataMapper
3
+ class HasProperty < Riot::AssertionMacro
4
+ register :has_property
5
+
6
+ def evaluate(model, field, *macro_info)
7
+ type, options = macro_info
8
+ property = model.properties[field]
9
+ fail_msg = "expected #{model} to have property :#{field}"
10
+ pass_msg = "#{model} has property :#{field}"
11
+ type_msg = " with type '#{type}'"
12
+ options_msg = " with options #{options.inspect}"
13
+
14
+ return fail(fail_msg) if property.nil?
15
+
16
+ if type
17
+ if property.class.to_s.include? type
18
+ pass_msg << type_msg
19
+ else
20
+ return fail(fail_msg + type_msg)
21
+ end
22
+ end
23
+
24
+ if options
25
+ mismatch = options.reject do |key,value|
26
+ property.method(key).call == value
27
+ end
28
+ if mismatch.empty?
29
+ pass_msg<<(options_msg)
30
+ else
31
+ return fail(fail_msg + options_msg)
32
+ end
33
+ end
34
+
35
+ pass(pass_msg)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ module Riot
2
+ module Datamapper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "riot-datamapper/version"
2
+
3
+ Dir[File.dirname(__FILE__) + '/riot-datamapper/*.rb'].each {|file| require file }
4
+
5
+ module Riot
6
+ module Datamapper
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "riot-datamapper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "riot-datamapper"
7
+ s.version = Riot::Datamapper::VERSION
8
+ s.authors = ["Arthur Chiu"]
9
+ s.email = ["mr.arthur.chiu@gmail.com"]
10
+ s.homepage = "https://www.github.com/achiu/riot-datamapper"
11
+ s.summary = %q{Riot Assertion Macros for DataMapper}
12
+ s.description = %q{Riot Assertion Macros for DataMapper}
13
+
14
+ s.rubyforge_project = "riot-datamapper"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'riot'
22
+ s.add_dependency 'dm-core'
23
+ s.add_dependency 'dm-validations'
24
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path('../teststrap', __FILE__)
2
+
3
+ context "has_property macro" do
4
+ setup do
5
+ Object.send(:remove_const, :FooBar) if Object.const_defined?(:FooBar)
6
+
7
+ class FooBar
8
+ include DataMapper::Resource
9
+
10
+ property :foo, String
11
+ property :bar, Serial
12
+ property :monkey, Boolean, :default => false
13
+ end
14
+ DataMapper.finalize ; FooBar
15
+ end
16
+
17
+ asserts "that it passes when the model has the property" do
18
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :bar).first
19
+ end.equals :pass
20
+
21
+ asserts "that it has message when it passes when the model has the property" do
22
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :bar).last
23
+ end.equals "FooBar has property :bar"
24
+
25
+ denies "that it passes when the model does not have the property" do
26
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :wahhh).first
27
+ end.equals :pass
28
+
29
+ asserts "that it passes when the model has the property and type" do
30
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :bar, 'Serial').first
31
+ end.equals :pass
32
+
33
+ asserts "that it has message when it passes when the model has the property and type" do
34
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :bar, 'Serial').last
35
+ end.equals "FooBar has property :bar with type 'Serial'"
36
+
37
+ denies "that it passes when the model does not have the property and type" do
38
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :bar, 'String').first
39
+ end.equals :pass
40
+
41
+ asserts "that it pass when the model has property, type, and options" do
42
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :monkey, 'Boolean', :default => false).first
43
+ end.equals :pass
44
+
45
+ asserts "that it pass when the model has property, type, and options" do
46
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :monkey, 'Boolean', :default => false).last
47
+ end.equals "FooBar has property :monkey with type 'Boolean' with options {:default=>false}"
48
+
49
+ denies "that it will pass when the model has property, type but not options" do
50
+ Riot::DataMapper::HasProperty.new.evaluate(topic, :monkey, 'Boolean', :required => true).first
51
+ end.equals :pass
52
+
53
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'riot'
2
+ require 'dm-core'
3
+ require 'dm-validations'
4
+ require File.expand_path('../../lib/riot-datamapper', __FILE__)
5
+
6
+ class Riot::Situation
7
+ end
8
+
9
+ class Riot::Context
10
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riot-datamapper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Arthur Chiu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-13 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: riot
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: dm-core
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: dm-validations
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: Riot Assertion Macros for DataMapper
49
+ email:
50
+ - mr.arthur.chiu@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - Rakefile
61
+ - lib/riot-datamapper.rb
62
+ - lib/riot-datamapper/has_property.rb
63
+ - lib/riot-datamapper/has_validation.rb
64
+ - lib/riot-datamapper/version.rb
65
+ - riot-datamapper.gemspec
66
+ - test/has_property_test.rb
67
+ - test/teststrap.rb
68
+ homepage: https://www.github.com/achiu/riot-datamapper
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: riot-datamapper
91
+ rubygems_version: 1.8.4
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Riot Assertion Macros for DataMapper
95
+ test_files:
96
+ - test/has_property_test.rb
97
+ - test/teststrap.rb