mongoa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Scott J. Tamosunas
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.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = mongoa
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Scott J. Tamosunas. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ #
4
+ # require 'rake/testtask'
5
+ # require 'rake/rdoctask'
6
+ #
7
+ # require 'rspec'
8
+ # require 'rspec/core'
9
+
10
+ begin
11
+ require 'jeweler'
12
+ Jeweler::Tasks.new do |gem|
13
+ gem.name = "mongoa"
14
+ gem.summary = %Q{Like Shoulda but for MongoMapper.}
15
+ gem.description = %Q{Adds the association and validation macros for Rspec in the same way Shoulda does for ActiveRecord.}
16
+ gem.email = "tamosunas@gmail.com"
17
+ gem.homepage = "http://github.com/scotttam/mongoa"
18
+ gem.authors = ["Scott J. Tamosunas"]
19
+ gem.add_development_dependency "rspec", ">= 1.2.9"
20
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
+ end
22
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ # require 'spec/rake/spectask'
28
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ # spec.libs << 'lib' << 'spec'
30
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ # end
32
+ #
33
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ # spec.libs << 'lib' << 'spec'
35
+ # spec.pattern = 'spec/**/*_spec.rb'
36
+ # spec.rcov = true
37
+ # end
38
+ #
39
+ # task :spec => :check_dependencies
40
+ #
41
+ # task :default => :spec
42
+ #
43
+ # require 'rake/rdoctask'
44
+ # Rake::RDocTask.new do |rdoc|
45
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+ #
47
+ # rdoc.rdoc_dir = 'rdoc'
48
+ # rdoc.title = "mongoa #{version}"
49
+ # rdoc.rdoc_files.include('README*')
50
+ # rdoc.rdoc_files.include('lib/**/*.rb')
51
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,8 @@
1
+ require 'mongoa/mongo_mapper/association_matcher'
2
+
3
+ module Mongoa
4
+ module MongoMapper
5
+ module Matchers
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,103 @@
1
+ module Mongoa
2
+ module MongoMapper
3
+ module Matchers
4
+ def belong_to(name)
5
+ MongoAssociationMatcher.new(:belongs_to, name)
6
+ end
7
+
8
+ def have_many(name)
9
+ MongoAssociationMatcher.new(:has_many, name)
10
+ end
11
+ end
12
+
13
+ class MongoAssociationMatcher
14
+ attr_reader :macro
15
+ attr_reader :name
16
+
17
+ #macro = belongs_to, has_many, etc
18
+ #name = template (right side of the relationship)
19
+ def initialize(macro, name)
20
+ @macro = macro
21
+ @name = name
22
+ end
23
+
24
+ def matches?(subject)
25
+ if subject.is_a?(String)
26
+ @expection = "You're subject is a string... it should be a Model constant. See your parent describe block."
27
+ return false
28
+ end
29
+ @subject = subject
30
+ association_exists? && macro_correct? && foreign_key_exists?
31
+ end
32
+
33
+ def failure_message
34
+ "Expected #{expectation} (#{@missing})"
35
+ end
36
+
37
+ def negative_failure_message
38
+ "Did not expect #{expectation}"
39
+ end
40
+
41
+ def negative_failure_message
42
+ "Did not expect #{expectation}"
43
+ end
44
+
45
+ def description
46
+ "#{macro_description} #{name}"
47
+ end
48
+
49
+ protected
50
+
51
+ def association
52
+ @association ||= model_class.find_association(name)
53
+ end
54
+
55
+ def model_class
56
+ p @subject
57
+ @subject.class
58
+ end
59
+
60
+ def expectation
61
+ @expectation ||= "#{model_class.name} to have a #{macro} association called #{name}"
62
+ end
63
+
64
+ def macro_description
65
+ case macro.to_s
66
+ when 'belongs_to' then 'belong to'
67
+ when 'has_many' then 'have many'
68
+ when 'has_one' then 'have one'
69
+ when 'has_and_belongs_to_many' then
70
+ 'have and belong to many'
71
+ end
72
+ end
73
+
74
+ def association_exists?
75
+ if !association
76
+ @missing = "no association called #{name}"
77
+ false
78
+ end
79
+ true
80
+ end
81
+
82
+ def association_exists?
83
+ association
84
+ end
85
+
86
+ def macro_correct?
87
+ association.type == macro
88
+ end
89
+
90
+ def foreign_key_exists?
91
+ !association.embeddable? && belongs_to_foreign_key_exists?
92
+ end
93
+
94
+ def belongs_to_foreign_key_exists?
95
+ macro == :belongs_to && model_class.keys.keys.include?("#{reflection_name}_id")
96
+ end
97
+
98
+ def reflection_name
99
+ @reflection ||= association.class_name.underscore
100
+ end
101
+ end
102
+ end
103
+ end
data/lib/mongoa.rb ADDED
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Matchers
3
+ include Mongoa::MongoMapper::Matchers
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Mongoa" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mongoa'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoa
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Scott J. Tamosunas
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-06 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Adds the association and validation macros for Rspec in the same way Shoulda does for ActiveRecord.
36
+ email: tamosunas@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/mongoa.rb
52
+ - lib/mongoa/matchers.rb
53
+ - lib/mongoa/mongo_mapper/association_matcher.rb
54
+ - spec/mongoa_spec.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/scotttam/mongoa
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Like Shoulda but for MongoMapper.
89
+ test_files:
90
+ - spec/mongoa_spec.rb
91
+ - spec/spec_helper.rb