Skip to content

Commit

Permalink
first big refactoring to made is more like the dm_rails implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe committed Mar 12, 2010
1 parent 5773fb8 commit 0b1be5a
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/felipe.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Thorfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# enconding: utf-8
require File.join(File.dirname(__FILE__), "lib", "couch_rails", "version")
require File.join(File.dirname(__FILE__), "lib", "couchrails", "support", "version")
require 'rubygems'
require 'bundler'
require 'thor/rake_compat'
require 'spec/rake/spectask'
begin
require 'rdoc/task'
rescue LoadError
end

Bundler.setup
Bundler.require(:default, :development)

GEM_NAME = 'couchrails'
EXTRA_RDOC_FILES = ["README", "LICENSE", "CHANGELOG.rdoc", "VERSION", "Thorfile"]

Expand Down
8 changes: 0 additions & 8 deletions lib/couch_rails/configuration.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/couch_rails/document.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/couch_rails.rb → lib/couchrails.rb
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
68 changes: 68 additions & 0 deletions lib/couchrails/active_model/couchrails_active_model.rb
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
60 changes: 60 additions & 0 deletions lib/couchrails/couchrails_active_model.rb
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.
39 changes: 39 additions & 0 deletions spec/amo_compliance_spec.rb
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
11 changes: 11 additions & 0 deletions spec/couchrails_active_model_spec.rb
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
25 changes: 0 additions & 25 deletions spec/document_spec.rb

This file was deleted.

6 changes: 6 additions & 0 deletions spec/models.rb
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
3 changes: 2 additions & 1 deletion spec/spec.opts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--color
--format specdoc
--colour
25 changes: 20 additions & 5 deletions spec/spec_helper.rb
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"

0 comments on commit 0b1be5a

Please sign in to comment.