-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first big refactoring to made is more like the dm_rails implementation
- Loading branch information
Felipe
committed
Mar 12, 2010
1 parent
5773fb8
commit 0b1be5a
Showing
15 changed files
with
215 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
require 'active_support' | ||
require 'active_model' | ||
require "couchrails/active_model/couchrails_active_model" | ||
|
||
module CouchRails | ||
autoload :Document, "couch_rails/document" | ||
autoload :AbstractClass, "couch_rails/support/abstract_class" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'active_model/naming' | ||
|
||
module CouchRails | ||
module ActiveModel | ||
|
||
|
||
module ClassMethods | ||
|
||
# Returns an ActiveModel::Name object for module. It can be | ||
# used to retrieve all kinds of naming-related information. | ||
def model_name | ||
@_model_name ||= ::ActiveModel::Name.new(self) | ||
end | ||
|
||
end | ||
|
||
|
||
module InstanceMethods | ||
|
||
def to_model | ||
self | ||
end | ||
|
||
def persisted? | ||
false | ||
end | ||
|
||
def to_key | ||
# key | ||
end | ||
|
||
def to_param | ||
# return nil if key.nil? | ||
# if key.length > 1 | ||
# raise "You need to implement #to_param yourself to support this key: #{self.class.key.inspect}" | ||
# else | ||
# self.key.first.to_s | ||
# end | ||
end | ||
|
||
# Define the minimum requirements if the resource | ||
# has no concept of validation baked in. | ||
unless respond_to?(:validatable?) | ||
|
||
def valid? | ||
true | ||
end | ||
|
||
def errors | ||
obj = Object.new | ||
|
||
def obj.[](key) | ||
[] | ||
end | ||
|
||
def obj.full_messages() | ||
[] | ||
end | ||
|
||
obj | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'active_model/naming' | ||
|
||
module CouchRails | ||
module ActiveModel | ||
|
||
|
||
# Returns an ActiveModel::Name object for module. It can be | ||
# used to retrieve all kinds of naming-related information. | ||
def model_name | ||
@_model_name ||= ::ActiveModel::Name.new(self) | ||
end | ||
|
||
|
||
def to_model | ||
self | ||
end | ||
|
||
def persisted? | ||
saved? | ||
end | ||
|
||
def to_key | ||
key | ||
end | ||
|
||
def to_param | ||
return nil if key.nil? | ||
if key.length > 1 | ||
raise "You need to implement #to_param yourself to support this key: #{self.class.key.inspect}" | ||
else | ||
self.key.first.to_s | ||
end | ||
end | ||
|
||
# Define the minimum requirements if the resource | ||
# has no concept of validation baked in. | ||
unless respond_to?(:validatable?) | ||
|
||
def valid? | ||
true | ||
end | ||
|
||
def errors | ||
obj = Object.new | ||
|
||
def obj.[](key) | ||
[] | ||
end | ||
|
||
def obj.full_messages() | ||
[] | ||
end | ||
|
||
obj | ||
end | ||
|
||
end | ||
end | ||
|
||
end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec/test/unit' | ||
|
||
# This must be kept in sync with active_model/lint tests | ||
# at least for as long as | ||
# | ||
# http://rspec.lighthouseapp.com/projects/5645/tickets/900 | ||
# | ||
# isn't resolved in some way (probably with rspec2) | ||
|
||
share_examples_for 'an active_model compliant object' do | ||
|
||
include ActiveModel::Lint::Tests | ||
|
||
it 'must implement the #to_key interface' do | ||
test_to_key | ||
end | ||
|
||
it 'must implement the #to_param interface' do | ||
test_to_param | ||
end | ||
|
||
it 'must implement the #valid? interface' do | ||
test_valid? | ||
end | ||
|
||
it 'must implement the #persisted? interface' do | ||
test_persisted? | ||
end | ||
|
||
it 'must implement the #model_naming interface' do | ||
test_model_naming | ||
end | ||
|
||
it 'must implement the #errors interface' do | ||
test_errors_aref | ||
test_errors_full_messages | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe 'An active_model compliant CouchRails::ActiveModel' do | ||
|
||
before :each do | ||
@model = ComplianceTest::CouchDocument.new.to_model | ||
end | ||
|
||
it_should_behave_like 'an active_model compliant object' | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module ComplianceTest | ||
class CouchDocument | ||
extend CouchRails::ActiveModel::ClassMethods | ||
include CouchRails::ActiveModel::InstanceMethods | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
--color | ||
--format specdoc | ||
--colour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
$TESTING=true | ||
begin | ||
# Just in case the bundle was locked | ||
# This shouldn't happen in a dev environment but lets be safe | ||
require File.expand_path('../../.bundle/environment', __FILE__) | ||
rescue LoadError | ||
require 'rubygems' | ||
require 'bundler' | ||
Bundler.setup | ||
end | ||
Bundler.require(:default, :test) | ||
|
||
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib")) | ||
lib = File.expand_path('../../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) if File.directory?(lib) | ||
|
||
require "couch_rails" | ||
# Use local active_model if running from a typical dev checkout. | ||
lib = File.expand_path('../../../rails/activemodel/lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) if File.directory?(lib) | ||
require 'active_model/lint' | ||
|
||
require 'rubygems' | ||
require 'rdoc' | ||
require "couchrails" | ||
require "amo_compliance_spec" | ||
|
||
require "models" |