mongo_doc-rails 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ LightMongo-Rails
2
+ ================
3
+
4
+ LightMongo-Rails provides ActionPack compatibility for [LightMongo][lm], allowing you to use form_for and other such helpers.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ `gem install light_mongo-rails`, assuming you already have LightMongo and Rails 3 on the boil.
10
+
11
+ Usage
12
+ -----
13
+
14
+ class MyModel
15
+ include LightMongo::Model
16
+ end
17
+
18
+ Then use like a normal LightMongo::Document.
19
+
20
+ NB: You are still welcome to include LightMongo::Document when in Rails, you just might hit some trouble using the ActionPack helpers.
21
+
22
+ [lm]:http://github.com/elliotcm/light_mongo
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "mongo_doc-rails"
7
+ gem.summary = "Rails 3 integration for MongoDoc"
8
+ gem.description = "MongoDoc-Rails provides an interface between the MongoDoc::Document and the Rails 3 ActionPack."
9
+ gem.email = "elliot.cm@gmail.com, leshill@gmail.com"
10
+ gem.homepage = "http://github.com/elliotcm/mongo_doc-rails"
11
+ gem.authors = ["Elliot Crosby-McCullough, Les Hill"]
12
+ gem.add_dependency "mongo_doc", ">=0.5.0"
13
+ gem.add_dependency "activemodel", ">=3.0.0.beta"
14
+ gem.add_development_dependency "rspec", "= 1.3.0"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+
18
+ task :spec => :check_dependencies
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
32
+ spec.libs << 'lib' << 'spec'
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,2 @@
1
+ require 'mongo_doc/active_model'
2
+ require 'mongo_doc'
@@ -0,0 +1,16 @@
1
+ require 'mongo_doc/active_model/active_model_compliance'
2
+ require 'mongo_doc/active_model/validations'
3
+
4
+ module MongoDoc
5
+ module ActiveModel
6
+ VERSION = '0.2.0'
7
+
8
+ def self.included(klass)
9
+ klass.class_eval do
10
+ include MongoDoc::Document
11
+ include MongoDoc::ActiveModel::ActiveModelCompliance
12
+ extend MongoDoc::ActiveModel::Validations::ClassMethods
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_model'
2
+
3
+ module MongoDoc
4
+ module ActiveModel
5
+ module ActiveModelCompliance
6
+ def destroyed?
7
+ _id.nil?
8
+ end
9
+
10
+ def self.included(klass)
11
+ klass.class_eval do
12
+ include ::ActiveModel::Validations
13
+ extend ::ActiveModel::Naming
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module MongoDoc
2
+ module ActiveModel
3
+ module Validations
4
+ module ClassMethods
5
+ def validates_embedded(*attr_names)
6
+ validates_with ValidatesEmbedded, _merge_attributes(attr_names)
7
+ end
8
+ end
9
+
10
+ class ValidatesEmbedded < ::ActiveModel::EachValidator
11
+ def validate(record)
12
+ attributes.each do |attr|
13
+ record.errors.add(attr) unless record.send(attr).valid?
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongo_doc-rails}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Elliot Crosby-McCullough, Les Hill"]
12
+ s.date = %q{2010-04-08}
13
+ s.description = %q{MongoDoc-Rails provides an interface between the MongoDoc::Document and the Rails 3 ActionPack.}
14
+ s.email = %q{elliot.cm@gmail.com, leshill@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/mongo_doc-rails.rb",
24
+ "lib/mongo_doc/active_model.rb",
25
+ "lib/mongo_doc/active_model/active_model_compliance.rb",
26
+ "lib/mongo_doc/active_model/validations.rb",
27
+ "mongo_doc-rails.gemspec",
28
+ "spec/active_model/active_model_compliance_spec.rb",
29
+ "spec/active_model/validations_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/elliotcm/mongo_doc-rails}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Rails 3 integration for MongoDoc}
38
+ s.test_files = [
39
+ "spec/active_model/active_model_compliance_spec.rb",
40
+ "spec/active_model/validations_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<mongo_doc>, [">= 0.5.0"])
50
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.beta"])
51
+ s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
52
+ else
53
+ s.add_dependency(%q<mongo_doc>, [">= 0.5.0"])
54
+ s.add_dependency(%q<activemodel>, [">= 3.0.0.beta"])
55
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<mongo_doc>, [">= 0.5.0"])
59
+ s.add_dependency(%q<activemodel>, [">= 3.0.0.beta"])
60
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ class ActiveModelComplianceTest
4
+ include MongoDoc::Document
5
+ end
6
+
7
+ describe MongoDoc::ActiveModel do
8
+ let(:model) { ActiveModelComplianceTest.new }
9
+
10
+ describe "#to_param" do
11
+ let(:string_id) { mock }
12
+
13
+ before(:each) do
14
+ model.instance_variable_set(:@_id, mock(:oid, :to_s => string_id))
15
+ end
16
+
17
+ it "returns the string form of the document id" do
18
+ model.to_param.should == string_id
19
+ end
20
+ end
21
+
22
+ describe "#valid?" do
23
+ subject { model }
24
+ it "responds to #valid?" do
25
+ should respond_to(:valid?)
26
+ end
27
+ end
28
+
29
+ describe "#new_record?" do
30
+ subject { model }
31
+ it "responds to #new_record?" do
32
+ should respond_to(:new_record?)
33
+ end
34
+
35
+ context "when the object has an id" do
36
+ before(:each) do
37
+ model.instance_variable_set(:@_id, mock(:id))
38
+ end
39
+
40
+ it "is false" do
41
+ should_not be_new_record
42
+ end
43
+ end
44
+
45
+ context "when the object has no id" do
46
+ before(:each) do
47
+ model.instance_variable_set(:@_id, nil)
48
+ end
49
+
50
+ it "is true" do
51
+ should be_new_record
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#destroyed?" do
57
+ subject { model }
58
+
59
+ it "responds to #destroyed?" do
60
+ should respond_to(:destroyed?)
61
+ end
62
+
63
+ context "when the object has an id" do
64
+ before(:each) do
65
+ model.instance_variable_set(:@_id, mock(:id))
66
+ end
67
+
68
+ it "is false" do
69
+ should_not be_destroyed
70
+ end
71
+ end
72
+
73
+ context "when the object has no id" do
74
+ before(:each) do
75
+ model.instance_variable_set(:@_id, nil)
76
+ end
77
+
78
+ it "is true" do
79
+ should be_destroyed
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#errors" do
85
+ subject { model }
86
+ it "responds to errors" do
87
+ should respond_to(:errors)
88
+ end
89
+
90
+ describe "#[]" do
91
+ it "returns an array on a missing key lookup" do
92
+ model.errors[:does_not_exist].should be_an(Array)
93
+ end
94
+ end
95
+
96
+ describe "#full_messages" do
97
+ it "returns an array" do
98
+ model.errors.full_messages.should be_an(Array)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe ".model_name" do
104
+ it "responds to model_name" do
105
+ ActiveModelComplianceTest.should respond_to(:model_name)
106
+ end
107
+
108
+ it "is a string" do
109
+ ActiveModelComplianceTest.model_name.should be_a(String)
110
+ end
111
+
112
+ it "has a human inflector" do
113
+ ActiveModelComplianceTest.model_name.human.should be_a(String)
114
+ end
115
+
116
+ it "has a partial path inflector" do
117
+ ActiveModelComplianceTest.model_name.partial_path.should be_a(String)
118
+ end
119
+
120
+ it "has a singular inflector" do
121
+ ActiveModelComplianceTest.model_name.singular.should be_a(String)
122
+ end
123
+
124
+ it "has a plural inflector" do
125
+ ActiveModelComplianceTest.model_name.plural.should be_a(String)
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe MongoDoc::ActiveModel::Validations do
4
+
5
+ class ValidationTest
6
+ extend MongoDoc::ActiveModel::Validations::ClassMethods
7
+ end
8
+
9
+ it "has the validates_embedded macro" do
10
+ ValidationTest.should respond_to(:validates_embedded)
11
+ end
12
+
13
+ describe MongoDoc::ActiveModel::Validations::ValidatesEmbedded do
14
+ let(:embedded) { stub(:null_object => true) }
15
+ let(:record) { stub(:name => embedded, :errors => stub(:null_object => true)) }
16
+ let(:validator) { MongoDoc::ActiveModel::Validations::ValidatesEmbedded.new(:attributes => :name) }
17
+
18
+ it "checks the validity of the named attribute" do
19
+ embedded.should_receive :valid?
20
+ validator.validate(record)
21
+ end
22
+
23
+ it "adds an invalid error if the named attribute is not valid" do
24
+ embedded.should_receive(:valid?).and_return(false)
25
+ record.errors.should_receive(:add).with(:name)
26
+ validator.validate(record)
27
+ end
28
+ end
29
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,7 @@
1
+ require 'active_support/core_ext'
2
+ require 'mongo_doc-rails'
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ Spec::Runner.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_doc-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 1
9
+ version: 0.2.1
10
+ platform: ruby
11
+ authors:
12
+ - Elliot Crosby-McCullough, Les Hill
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-08 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mongo_doc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 0
31
+ version: 0.5.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activemodel
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 3
43
+ - 0
44
+ - 0
45
+ - beta
46
+ version: 3.0.0.beta
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 3
59
+ - 0
60
+ version: 1.3.0
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: MongoDoc-Rails provides an interface between the MongoDoc::Document and the Rails 3 ActionPack.
64
+ email: elliot.cm@gmail.com, leshill@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.md
71
+ files:
72
+ - .gitignore
73
+ - README.md
74
+ - Rakefile
75
+ - VERSION
76
+ - lib/mongo_doc-rails.rb
77
+ - lib/mongo_doc/active_model.rb
78
+ - lib/mongo_doc/active_model/active_model_compliance.rb
79
+ - lib/mongo_doc/active_model/validations.rb
80
+ - mongo_doc-rails.gemspec
81
+ - spec/active_model/active_model_compliance_spec.rb
82
+ - spec/active_model/validations_spec.rb
83
+ - spec/spec.opts
84
+ - spec/spec_helper.rb
85
+ has_rdoc: true
86
+ homepage: http://github.com/elliotcm/mongo_doc-rails
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --charset=UTF-8
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.6
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Rails 3 integration for MongoDoc
115
+ test_files:
116
+ - spec/active_model/active_model_compliance_spec.rb
117
+ - spec/active_model/validations_spec.rb
118
+ - spec/spec_helper.rb