light_mongo-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README +0 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/lib/light_mongo-rails.rb +1 -0
- data/lib/model/active_model_compliance.rb +44 -0
- data/lib/model.rb +12 -0
- data/spec/model/active_model_compliance_spec.rb +119 -0
- metadata +82 -0
data/.gitignore
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "light_mongo-rails"
|
8
|
+
gem.summary = "Rails 3 integration for LightMongo"
|
9
|
+
gem.description = "LightMongo-Rails provides an interface between the LightMongo::Document and the Rails 3 ActionPack."
|
10
|
+
gem.email = "elliot.cm@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/elliotcm/light_mongo-rails"
|
12
|
+
gem.authors = ["Elliot Crosby-McCullough"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.3.0"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
|
17
|
+
task :spec => :check_dependencies
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
spec.spec_opts = ['--color']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
spec.spec_opts = ['--color']
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'model'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'active_model/naming'
|
4
|
+
|
5
|
+
require 'active_model/deprecated_error_methods'
|
6
|
+
require 'active_model/errors'
|
7
|
+
|
8
|
+
# Still missing from complete ActionPack integration is
|
9
|
+
# validations, which I've left out of this "barebones"
|
10
|
+
# compliance, and translations, which might be worth
|
11
|
+
# bundling in the future.
|
12
|
+
|
13
|
+
module LightMongo
|
14
|
+
module Model
|
15
|
+
|
16
|
+
module ActiveModelCompliance
|
17
|
+
# Replace this with your own validations.
|
18
|
+
def valid?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
# There is currently no useful difference
|
23
|
+
# between a new record and a destroyed record.
|
24
|
+
#
|
25
|
+
# As such, these methods are essentially synonymous.
|
26
|
+
def new_record?
|
27
|
+
@_id.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroyed?
|
31
|
+
@_id.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def errors
|
35
|
+
@errors ||= ActiveModel::Errors.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.included(doc_class)
|
39
|
+
doc_class.extend ActiveModel::Naming
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/model.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../lib/model/active_model_compliance'
|
2
|
+
|
3
|
+
ActiveModelCompliance = LightMongo::Model::ActiveModelCompliance
|
4
|
+
|
5
|
+
class ActiveModelComplianceTest
|
6
|
+
include LightMongo::Model::ActiveModelCompliance
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ActiveModelCompliance do
|
10
|
+
before(:each) do
|
11
|
+
@model = ActiveModelComplianceTest.new
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#valid?" do
|
15
|
+
it "responds to #valid?" do
|
16
|
+
@model.should respond_to(:valid?)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "always returns true" do
|
20
|
+
@model.valid?.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#new_record?" do
|
25
|
+
it "responds to #new_record?" do
|
26
|
+
@model.should respond_to(:new_record?)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when the object has an id" do
|
30
|
+
before(:each) do
|
31
|
+
@model.instance_variable_set(:@_id, mock(:id))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is false" do
|
35
|
+
@model.new_record?.should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the object has no id" do
|
40
|
+
before(:each) do
|
41
|
+
@model.instance_variable_set(:@_id, nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is true" do
|
45
|
+
@model.new_record?.should be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#destroyed?" do
|
51
|
+
it "responds to #destroyed?" do
|
52
|
+
@model.should respond_to(:destroyed?)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the object has an id" do
|
56
|
+
before(:each) do
|
57
|
+
@model.instance_variable_set(:@_id, mock(:id))
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is false" do
|
61
|
+
@model.destroyed?.should be_false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when the object has no id" do
|
66
|
+
before(:each) do
|
67
|
+
@model.instance_variable_set(:@_id, nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "is true" do
|
71
|
+
@model.destroyed?.should be_true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#errors" do
|
77
|
+
it "responds to errors" do
|
78
|
+
@model.should respond_to(:errors)
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#[]" do
|
82
|
+
it "returns an array on a missing key lookup" do
|
83
|
+
@model.errors[:does_not_exist].should be_an(Array)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#full_messages" do
|
88
|
+
it "returns an array" do
|
89
|
+
@model.errors.full_messages.should be_an(Array)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe ".model_name" do
|
95
|
+
it "responds to model_name" do
|
96
|
+
ActiveModelComplianceTest.should respond_to(:model_name)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is a string" do
|
100
|
+
ActiveModelComplianceTest.model_name.should be_a(String)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "has a human inflector" do
|
104
|
+
ActiveModelComplianceTest.model_name.human.should be_a(String)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "has a partial path inflector" do
|
108
|
+
ActiveModelComplianceTest.model_name.partial_path.should be_a(String)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "has a singular inflector" do
|
112
|
+
ActiveModelComplianceTest.model_name.singular.should be_a(String)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "has a plural inflector" do
|
116
|
+
ActiveModelComplianceTest.model_name.plural.should be_a(String)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: light_mongo-rails
|
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
|
+
- Elliot Crosby-McCullough
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-27 00:00:00 +00: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
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 1.3.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: LightMongo-Rails provides an interface between the LightMongo::Document and the Rails 3 ActionPack.
|
35
|
+
email: elliot.cm@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- README
|
45
|
+
- Rakefile
|
46
|
+
- VERSION
|
47
|
+
- lib/light_mongo-rails.rb
|
48
|
+
- lib/model.rb
|
49
|
+
- lib/model/active_model_compliance.rb
|
50
|
+
- spec/model/active_model_compliance_spec.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/elliotcm/light_mongo-rails
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Rails 3 integration for LightMongo
|
81
|
+
test_files:
|
82
|
+
- spec/model/active_model_compliance_spec.rb
|