Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails3.2 #1

Open
wants to merge 6 commits into
base: rails3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3
16 changes: 8 additions & 8 deletions couchrest_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency(%q<couchrest>, "~> 1.1.2")
s.add_dependency(%q<mime-types>, "~> 1.15")
s.add_dependency(%q<activemodel>, "~> 3.0")
s.add_dependency(%q<tzinfo>, "~> 0.3.22")
s.add_development_dependency(%q<rspec>, "~> 2.6.0")
s.add_development_dependency(%q<json>, ["~> 1.5.1"])
s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
s.add_development_dependency("rake", ">= 0.8.0")
s.add_dependency(%q<couchrest>, ">= 1.1.2")
s.add_dependency(%q<mime-types>, ">= 1.18")
s.add_dependency(%q<activemodel>, ">= 3.2")
s.add_dependency(%q<tzinfo>, ">= 0.3.32")
s.add_development_dependency(%q<rspec>, ">= 2.7.0")
s.add_development_dependency(%q<json>, [">= 1.6.6"])
s.add_development_dependency(%q<rack-test>, ">= 0.6.1")
s.add_development_dependency("rake", ">= 0.9.2")
# s.add_development_dependency("jruby-openssl", ">= 0.7.3")
end

4 changes: 4 additions & 0 deletions lib/couchrest/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def to_key
new? ? nil : [id]
end

def to_partial_path
@_to_partial_path ||= self.class.name.demodulize.underscore
end

alias :to_param :id
alias :new_record? :new?
alias :new_document? :new?
Expand Down
2 changes: 1 addition & 1 deletion lib/couchrest_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
# Add rails support *after* everything has loaded
if defined?(Rails)
require "couchrest/railtie"
end
end
3 changes: 2 additions & 1 deletion spec/unit/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@

it 'should return a Hash with all attachments' do
@file.rewind
@obj.attachments.should == { @attachment_name =>{ "data" => "PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPHRpdGxlPlRlc3Q8L3RpdGxlPgogIDwvaGVhZD4KICA8Ym9keT4KICAgIDxwPgogICAgICBUZXN0CiAgICA8L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==", "content_type" => "text/html"}}
b64_file_contents = Base64.encode64( @file.read ).split("\n").join
@obj.attachments.should == { @attachment_name =>{ "data" => b64_file_contents, "content_type" => "text/html"}}
end

end
Expand Down
45 changes: 28 additions & 17 deletions spec/unit/design_doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,24 @@
class_name = "#{example.metadata[:full_description].gsub(/\s+/,'_').camelize}Model"
doc = CouchRest::Document.new("_id" => "_design/#{class_name}")
doc["language"] = "javascript"
doc["views"] = {"all" => {"map" =>
"function(doc) {
if (doc['type'] == 'Article') {
emit(doc['_id'],1);
}
}"},
"by_name" => {"map" =>
"function(doc) {
if ((doc['type'] == '#{class_name}') && (doc['name'] != null)) {
emit(doc['name'], null);
}",
"reduce" =>
"function(keys, values, rereduce) {
return sum(values);
}"}}
doc["views"] = {
"all" => {"map" =>
"function(doc) {
if (doc['type'] == 'Article') {
emit(doc['_id'],1);
}
}"},
"by_name" => {"map" =>
"function(doc) {
if ((doc['type'] == 'special') && (doc['name'] != null)) {
emit(doc['name'], null);
}}",
"reduce" =>
"function(keys, values, rereduce) {
return sum(values);
}"
}
}

DB.save_doc doc

Expand All @@ -193,15 +196,23 @@ class ::#{class_name} < CouchRest::Model::Base
view :by_name
end
property :name, String

def self.reload_design_doc
@design_doc = nil
end
end
KLASS

class_name.constantize
new_model = class_name.constantize

new_model.reload_design_doc
new_model
}

it "will not update stored design doc if view changed" do
model_class.by_name
orig = model_class.stored_design_doc
model_class.auto_update_design_doc.should == false
design = model_class.design_doc
view = design['views']['by_name']['map']
design['views']['by_name']['map'] = view + ' '
Expand All @@ -220,7 +231,7 @@ class ::#{class_name} < CouchRest::Model::Base
end

it "is able to use predefined views" do
model_class.by_name(key: "special").all
model_class.by_name(:key => "special").all
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/dirty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def code; self['_id'] || @code; end
describe "changes" do

it "should return changes on an attribute" do
@card = Card.new(:first_name => "matt")
@card = Card.create(:first_name => "matt")
@card.first_name = "andrew"
@card.first_name_changed?.should be_true
@card.changes.should == { "first_name" => ["matt", "andrew"] }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/inherited_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'spec_helper'

class PlainParent
class_inheritable_accessor :foo
class_attribute :foo
self.foo = :bar
end

class PlainChild < PlainParent
end

class ExtendedParent < CouchRest::Model::Base
class_inheritable_accessor :foo
class_attribute :foo
self.foo = :bar
end

Expand Down