Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated for mongoid-2.0.0.rc.6

Association renamed to Relation
Removed Jeweler in favor of Bundler
  • Loading branch information...
commit b1b0a5ea370b53936b9b84b5e7e7af187724f1d4 1 parent 3d5c134
Brian Cardarella authored
27 .gitignore
View
@@ -1,25 +1,4 @@
-## MAC OS
-.DS_Store
-
-## TEXTMATE
-*.tmproj
-tmtags
-
-## EMACS
-*~
-\#*
-.\#*
-
-## VIM
-*.swp
-
-## BUNDLER
+*.gem
+.bundle
Gemfile.lock
-.bundle/
-
-## PROJECT::GENERAL
-coverage
-rdoc
-pkg
-
-## PROJECT::SPECIFIC
+pkg/*
5 Gemfile
View
@@ -1,3 +1,4 @@
-source :rubygems
+source "http://rubygems.org"
-gemspec
+# Specify your gem's dependencies in ..gemspec
+gemspec
29 Rakefile
View
@@ -1,27 +1,2 @@
-require 'rubygems'
-require 'rake'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "remarkable_mongoid"
- gem.summary = %Q{RSpec Matchers for Mongoid}
- gem.description = %Q{RSpec Matchers for Mongoid}
- gem.email = "bcardarella@gmail.com"
- gem.homepage = "http://github.com/bcardarella/remarkable_mongoid"
- gem.authors = ["Brian Cardarella"]
- gem.files = Dir.glob("lib/**/*") + %w(LICENSE README.markdown)
- gem.test_files = []
- gem.add_dependency 'remarkable_activemodel', '>=4.0.0.alpha2'
-
- gem.add_development_dependency 'ruby-debug'
- gem.add_development_dependency 'bson_ext'
- gem.add_development_dependency 'activesupport', '3.0.1'
- gem.add_development_dependency 'mongoid', '2.0.0.beta.19'
- gem.add_development_dependency 'rspec', '2.0.0'
- gem.add_development_dependency 'bourne', '1.0'
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
+require 'bundler'
+Bundler::GemHelper.install_tasks'
2  lib/remarkable/mongoid.rb
View
@@ -5,7 +5,7 @@ module Mongoid
require 'remarkable/active_model'
require 'remarkable/mongoid/fields'
-require 'remarkable/mongoid/associations'
+require 'remarkable/mongoid/relations'
require 'remarkable/mongoid/validate_uniqueness_of'
require 'remarkable/mongoid/validate_association'
60 lib/remarkable/mongoid/associations.rb
View
@@ -1,60 +0,0 @@
-module Remarkable::Mongoid
- module Matchers
- def reference_one(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesOne)
- end
-
- def reference_many(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesMany)
- end
-
- def reference_many_as_array(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesManyAsArray)
- end
-
- def be_referenced_in(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencedIn)
- end
-
- def embed_one(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsOne)
- end
-
- def embed_many(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsMany)
- end
-
- def be_embedded_in(attr)
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbeddedIn)
- end
-
- class AssociationMatcher
- attr_accessor :attr, :association_type
-
- def initialize(attr, association_type)
- self.attr = attr.to_s
- self.association_type = association_type
- end
-
- def matches?(subject)
- @subject = subject
- associations = @subject.associations.select { |k,v| v.association == association_type }
- associations.detect { |k| k.first == attr } != nil
- end
-
- def description
- "has #{humanized_association} association :#{attr}"
- end
-
- def failure_message_for_should
- "\n#{humanized_association} association failure\nExpected: '#{attr}'"
- end
-
- private
-
- def humanized_association
- association_type.to_s.split('::').last
- end
- end
- end
-end
4 lib/remarkable/mongoid/fields.rb
View
@@ -9,11 +9,11 @@ class HasFieldMatcher
def initialize(field, options)
self.field = field.to_s
- self.options = { :type => String }.merge(options)
+ self.options = { :type => Object }.merge(options)
end
def matches?(subject)
- @subject = subject.is_a?(Class) ? subject : subject.class
+ @subject = subject.is_a?(Class) ? subject : subject.class
@subject.fields.has_key?(field) && (@subject.fields[field].type == options[:type])
end
60 lib/remarkable/mongoid/relations.rb
View
@@ -0,0 +1,60 @@
+module Remarkable::Mongoid
+ module Matchers
+ def reference_one(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::One)
+ end
+
+ def reference_many(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::Many)
+ end
+
+ def reference_many_as_array(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::ManyToMany)
+ end
+
+ def be_referenced_in(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::In)
+ end
+
+ def embed_one(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::One)
+ end
+
+ def embed_many(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::Many)
+ end
+
+ def be_embedded_in(attr)
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::In)
+ end
+
+ class RelationMatcher
+ attr_accessor :attr, :relation_type
+
+ def initialize(attr, relation_type)
+ self.attr = attr.to_s
+ self.relation_type = relation_type
+ end
+
+ def matches?(subject)
+ @subject = subject
+ relations = @subject.relations.select { |k,v| v.relation == relation_type }
+ relations.detect { |k| k.first == attr } != nil
+ end
+
+ def description
+ "has #{humanized_relation} relation :#{attr}"
+ end
+
+ def failure_message_for_should
+ "\n#{humanized_relation} relation failure\nExpected: '#{attr}'"
+ end
+
+ private
+
+ def humanized_relation
+ relation_type.to_s.split('::').last
+ end
+ end
+ end
+end
5 lib/remarkable/mongoid/version.rb
View
@@ -0,0 +1,5 @@
+module Remarkable
+ module Mongoid
+ VERSION = '0.5.1'
+ end
+end
84 remarkable_mongoid.gemspec
View
@@ -1,65 +1,35 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'remarkable/mongoid/version'
Gem::Specification.new do |s|
- s.name = %q{remarkable_mongoid}
- s.version = "0.5.0"
+ s.name = 'remarkable_mongoid'
+ s.version = Remarkable::Mongoid::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['Brian Cardarella']
+ s.email = ['bcardarella@gmail.com']
+ s.homepage = 'https://github.com/bcardarella/remarkable_mongoid'
+ s.description = 'RSpec Matchers for Mongoid'
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Brian Cardarella"]
- s.date = %q{2010-10-15}
- s.description = %q{RSpec Matchers for Mongoid}
- s.email = %q{bcardarella@gmail.com}
- s.extra_rdoc_files = [
- "LICENSE",
- "README.markdown"
- ]
- s.files = [
- "LICENSE",
- "README.markdown",
- "lib/remarkable/mongoid.rb",
- "lib/remarkable/mongoid/associations.rb",
- "lib/remarkable/mongoid/fields.rb",
- "lib/remarkable/mongoid/validate_association.rb",
- "lib/remarkable/mongoid/validate_uniqueness_of.rb"
- ]
- s.homepage = %q{http://github.com/bcardarella/remarkable_mongoid}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{RSpec Matchers for Mongoid}
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ['lib']
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<remarkable_activemodel>, [">= 4.0.0.alpha2"])
- s.add_development_dependency(%q<ruby-debug>, [">= 0"])
- s.add_development_dependency(%q<bson_ext>, [">= 0"])
- s.add_development_dependency(%q<activesupport>, ["= 3.0.1"])
- s.add_development_dependency(%q<mongoid>, ["= 2.0.0.beta.19"])
- s.add_development_dependency(%q<rspec>, ["= 2.0.0"])
- s.add_development_dependency(%q<bourne>, ["= 1.0"])
- else
- s.add_dependency(%q<remarkable_activemodel>, [">= 4.0.0.alpha2"])
- s.add_dependency(%q<ruby-debug>, [">= 0"])
- s.add_dependency(%q<bson_ext>, [">= 0"])
- s.add_dependency(%q<activesupport>, ["= 3.0.1"])
- s.add_dependency(%q<mongoid>, ["= 2.0.0.beta.19"])
- s.add_dependency(%q<rspec>, ["= 2.0.0"])
- s.add_dependency(%q<bourne>, ["= 1.0"])
- end
- else
- s.add_dependency(%q<remarkable_activemodel>, [">= 4.0.0.alpha2"])
- s.add_dependency(%q<ruby-debug>, [">= 0"])
- s.add_dependency(%q<bson_ext>, [">= 0"])
- s.add_dependency(%q<activesupport>, ["= 3.0.1"])
- s.add_dependency(%q<mongoid>, ["= 2.0.0.beta.19"])
- s.add_dependency(%q<rspec>, ["= 2.0.0"])
- s.add_dependency(%q<bourne>, ["= 1.0"])
+ s.add_dependency 'remarkable_activemodel', '~> 4.0.0.alpha4'
+
+ s.add_development_dependency 'bson_ext'
+ s.add_development_dependency 'activesupport', '~> 3.0.0'
+ s.add_development_dependency 'mongoid', '~> 2.0.0.rc.6'
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'bourne'
+
+ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
+ if ruby_minor_version == 8
+ s.add_development_dependency 'ruby-debug'
+ elsif ruby_minor_version == 9
+ s.add_development_dependency 'ruby-debug19'
end
-end
+end
53 spec/associations_spec.rb → spec/relations_spec.rb
View
@@ -1,29 +1,31 @@
require 'spec_helper'
-describe 'Mongoid Associations' do
+describe 'Mongoid Relations' do
before :all do
class Should
include Remarkable::Mongoid::Matchers
end
-
+
@should = Should.new
end
context 'embedding' do
before :all do
class SingleBook
- include Mongoid::Associations
+ include Mongoid::Document
+
embeds_many :pages, :class_name => "SinglePage"
- embed_one :author, :class_name => "SingleAuthor"
+ embeds_one :author, :class_name => "SingleAuthor"
end
class SinglePage
- include Mongoid::Associations
+ include Mongoid::Document
+
embedded_in :book, :clas_name => "SingleBook", :inverse_of => :pages
end
end
- describe 'embed_one' do
+ describe 'embeds_one' do
it 'should be true for a book embedding one author' do
matcher = @should.embed_one :author
matcher.matches?(SingleBook.new).should be_true
@@ -63,34 +65,21 @@ class SinglePage
context 'referencing' do
before :all do
class SingleOwner
- def self.set_callback(*args); end
- def self.add_dirty_methods(*args); end
- def self.index(*args); end
- def self.using_object_ids?; true; end
- include Mongoid::Fields
- include Mongoid::Associations
- references_many :dogs, :class_name => "SingleDog"
- references_many :turtles, :class_name => "SingleTurtle", :stored_as => :array
- references_one :friend, :class_name => "SingleFriend"
+ include Mongoid::Document
+
+ references_many :dogs, :class_name => "SingleDog"
+ references_one :friend, :class_name => "SingleFriend"
+ references_and_referenced_in_many :turtles, :class_name => "SingleTurtle"
end
class SingleDog
- def self.set_callback(*args); end
- def self.add_dirty_methods(*args); end
- def self.index(*args); end
- def self.using_object_ids?; true; end
- include Mongoid::Fields
- include Mongoid::Associations
+ include Mongoid::Document
+
referenced_in :owner, :class_name => "SingleOwner", :inverse_of => :dogs
end
class SingleTurtle
- def self.set_callback(*args); end
- def self.add_dirty_methods(*args); end
- def self.index(*args); end
- def self.using_object_ids?; true; end
- include Mongoid::Fields
- include Mongoid::Associations
+ include Mongoid::Document
end
end
@@ -148,17 +137,17 @@ def self.using_object_ids?; true; end
context 'messages' do
before do
- @association_matcher = Remarkable::Mongoid::Matchers::AssociationMatcher.new(:test, "Some::Test")
+ @relation_matcher = Remarkable::Mongoid::Matchers::RelationMatcher.new(:test, "Some::Test")
end
describe 'description' do
- subject { @association_matcher.description }
- it { should == "has Test association :test" }
+ subject { @relation_matcher.description }
+ it { should == "has Test relation :test" }
end
describe 'failure_message_for_should' do
- subject { @association_matcher.failure_message_for_should }
- it { should == "\nTest association failure\nExpected: 'test'"}
+ subject { @relation_matcher.failure_message_for_should }
+ it { should == "\nTest relation failure\nExpected: 'test'"}
end
end
end
1  spec/spec_helper.rb
View
@@ -5,6 +5,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'ruby-debug'
+require 'rubygems'
require 'remarkable/mongoid'
require 'mongoid'
require 'rspec'
Please sign in to comment.
Something went wrong with that request. Please try again.