GithubHelp home page GithubHelp logo

couch_potato's People

Contributors

andrewtimberlake avatar andymorris avatar arbovm avatar bernd avatar bterkuile avatar code-later avatar dodecaphonic avatar freetwix avatar froderik avatar jhohertz-work avatar jweiss avatar langalex avatar luminapower avatar matthiasjakel avatar mmbenny avatar omegahm avatar peritor avatar phoet avatar roidrage avatar speedmax avatar sporkd avatar subandik avatar thilo avatar weppos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

couch_potato's Issues

if/unless option for callbacks

allow something like after_create :do_something, :if => :do_it?

should also work with a lambda instead of a symbol as condition

Rails 2 Incompatibility

Starting with versions > 0.3.0 activemodel has been listed as a dependency. It tries to pull down activesupport > 3.0.0 which generally makes this gem incompatible with Rails 2. Is there any way to skip listing that dependency in the gemspec?

Use false as field's default value

Am I missing something, or there's a bug when defining default value as false? When I create new instance, I get nil in corresponding field.

Getting a TypeError after save

Am I doing something wrong? I created a simple persistent object using couch_potato, set a property on it, and when I save it I get the following:

TypeError: can’t convert String into Integer
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence.rb:130:in `[]’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence.rb:130:in`extract_rev’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence.rb:143:in `update_document’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence/bulk_save_queue.rb:38:in`call’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence/bulk_save_queue.rb:38:in `save’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence/bulk_save_queue.rb:37:in`each’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence/bulk_save_queue.rb:37:in `save’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence.rb:142:in`update_document’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence.rb:64:in `save’
from /Library/Ruby/Gems/1.8/gems/langalex-couch_potato-0.1.1/lib/couch_potato/persistence/dirty_attributes.rb:6:in`save’
from (irb):6

`load_document` loads `_all_docs` instead of directly querying the document

I was debugging some of my CouchDB views when I realized that couch_potato's load_document triggers a query to http://host:port/db/_all_docs?include_docs=true and grabs the document from that view.

Is it normal? Fetching the document directly would be a lot faster way IMHO, like loading http://host:port/db/id instead.

running callbacks changes answer of valid?

i just looked for a bug in our app that works along with devise and a before_validation_on_create callback.

in our user model we trigger a callback to set some data:

before_validation_on_create do
  self.one_click_token = Devise.friendly_token unless self.one_click_token
  self.site_code = Wlw.site_code unless self.site_code
end

and when devise saves the user model, the e-mail validation won't get triggered.

i drilled it down to create_document where all the callbacks are run:

      if validate
        document.errors.clear
        return false if false == document.run_callbacks(:validation_on_save) do
          return false if false == document.run_callbacks(:validation_on_create) do
            return false unless valid_document?(document)
          end
        end
      end

the funny part is, that before running the :validation_on_create callback document.valid? is false and after that it's true?!

changing something on the document results in the valid? method to return false again.

any ideas?

Nested changes

Changes in properties whose type also mixes in CouchPotato::Persistence, or array properties, are not reflected in the root object's #changes method. This complicates code like the following:

plant = db.load_document(id)
plant.branch.leafs = 3
db.save plant # does not save because plant.changes is empty

plant.array_property << new_value
db.save plant # again plant.changes is empty

#is_dirty exists to help with this, but it would also be nice to have a way to get deep/nested changes for auditing and other purposes. I plan on implementing this and would like to see it pulled into the project.

One question though: should a new method be added to get these changes (top level + nested) for purposes of backward and ActiveModel compatibility? Or should the existing #changes method be modified to also include nested changes? Or maybe it can be opt-in by including a DeepChanges module that overwrites #changes and related methods?

Validation incompatible with ActiveModel::Errors in Rails 3.1

ActiveModel::Errors no longer subclasses OrderedHash as of 3.1:
hhttps://github.com/rails/rails/commit/307e6b2b74ba3ae72602dc33e6d45cd3e46181c7#activemodel/lib/active_model/errors.rb

Thus #each_pair is no longer implemented and CouchPotato::Database#valid_document? raises a NoMethodError.

I'll investigate a fix when I get a chance but wanted to go ahead and raise the flag.

NoMethodError when typed property is null

If I have a property that is typed as something, like an Array, and the field is nil, then when I run a query against the database, I get a NoMethodError.

db.view Product.all
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/json-1.1.7/lib/json/add/rails.rb:12:in json_create' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/persistence/simple_property.rb:53:inbuild'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/persistence/json.rb:38:in block in json_create' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/persistence/json.rb:37:ineach'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/persistence/json.rb:37:in json_create' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/persistence/properties.rb:31:injson_create'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/view/model_view_spec.rb:38:in block in process_results' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/view/model_view_spec.rb:37:inmap'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/view/model_view_spec.rb:37:in process_results' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/langalex-couch_potato-0.2.7/lib/couch_potato/database.rb:19:inview'
from (irb):6
from /opt/local/bin/irb:12:in `

'

I am normally pretty good at finding these errors, but I am running Ruby 1.9.1, so I don't have the luxury of ruby-debug.

Properties instantiated as null in couchDB if not set

Hi;

I have a model of a user with a first name and last name field. From what I understand of couchDB, if i set the first_name but not the last name, the document in the database should ONLY contain the first name field - However it looks like the last_name field also gets instantiated with a NULL value. Can you clarify if this is expected behaviour?

README mentions #create but I cannot find it

As proposed by the README, I created a class:

class User
  include CouchPotato::Persistence
end

But when I try to create a user, I get

NoMethodError: undefined method `create' for User:Class

This is documented in the README section "Dirty tracking." Am I missing something? Or did the method get thrown out?

Variable JSON.create_id

It would be nice to have a variable value for the ruby_class key in documents. This way it would be easier to share access to a single couchdb with different clients. I think it should be fairly easy, since one could simply override the JSON.create_id per application and use this value within specs and the view code generation for properties and models. I spotted some places in the code where this isn't used yet and made a diff of the changes.

Specs are still passing, so you might want to integrate the changes.

See this gist for the diff

lists are not auto updated

when i do CouchPotato.database.view(SomeClass.some_view(list: :some_list)) then some_list doesn't get updated automatically

nested models don't get validated

we are currently switching from couchrest_model to couch_potato. while doing this our tests failed because couch_potato is not validating 'nested' models. since this is working with the other framework i am not sure if this complies to the contract of active-model validation or not. i would expect that errors on nested models should also fail the validation of the parent and have their errors collected.

here is an example:

class Nested
  include CouchPotato::Persistence

  property :val
  validates :val, :presence => true
end


class Model
  include CouchPotato::Persistence

  property :val
  property :nested, :type => Nested

  validates :val, :presence => true
end

m = Model.new
puts m.valid?
puts m.errors.messages
m.nested = Nested.new
puts m.valid?
puts m.errors.messages
puts m.nested.valid?
puts m.nested.errors.messages
m.val = 'name'
puts m.valid?
puts m.errors.messages
puts m.nested.valid?
puts m.nested.errors.messages

output:

false
{:val=>["can't be blank"]}
false
{:val=>["can't be blank"]}
false
{:val=>["can't be blank"]}
true
{}
false
{:val=>["can't be blank"]}

wrong view-data problem in test context

when executing spec in a specific order, there was an error when using views.

it looks as if the problem was within the view invalidation logic within ViewQuery

this spec reproduces the error:

require 'spec_helper'

class Build
  include CouchPotato::Persistence

  property :site_code

  view :by_site_code, :key => :site_code, :reduce => true
end

describe "automatic view updates" do
  before(:each) do
    recreate_db
  end

  it "should return a valid result after view-update" do
    10.times { CouchPotato.database.save_document Build.new(:site_code => 'DE') }
    CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
    CouchPotato::View::ViewQuery.class_variable_get(:@@updated_views).should eql({})
    CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
    CouchPotato::View::ViewQuery.class_variable_get(:@@updated_views).should eql({["build", "by_site_code"]=>true})
    CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
    recreate_db
    10.times { CouchPotato.database.save_document Build.new(:site_code => 'DE') }
    # broken, returns 10 instead of 0 expected
    CouchPotato.database.view(Build.by_site_code(:keys => ['EN'], :include_docs => false)).size.should eql(0)
  end
end

CouchPotato is not saving nil attributes - This breaks the default views

CouchPototo discards nil attributes before saving, thus removing these attributes from the JSON document. Apart from being not what I expect (I did specify the attribute as a property, and the property is nil. But still it is a property), it breaks the query views (or better said, the map function):

class User
include CouchPotato::Persistence

property :name

view :by_name, :key => :name
end

:name is optional here, but this results in an exception in CouchDB if you have users with no name:

User.find_by_name('foo')

The problem is the map function:

emit(doc['name'], null)

doc['name'] is undefined which raises a JSON serialization exception.

I think the correct way is to store the nil attribute as null. This way the above map function works as expected and the JSON document looks as expected.

I've fixed it here:

http://github.com/jweiss/couch_potato/commit/9e8fce04656d1d86793b276a34f66336d89166e5

Jonathan

Encoding issue

AFAICS, CouchPotato doesn't allow the usage of UTF-8 characters. If I try to set, say "šđčćž" as a title of my document, I get invalid field.

Using array key to query fails

I have used previous version of couch_potato before its major rewrite, separating database operations do help ease on testing, but finger kinda hurts compare to the older version, i guess its a matter of judging how much automagic u need Vs. performance,

One of the thing that last major version works is using array as a key.. so you can do operations like following and it builds the map function as well as conversion of date range object into key.

Person.all(:key => [project.id, 10.days.ago .. 0.day.ago]) 

It kinda stopped working, i start poke around specs (custom_view_spec) and added following, It failes along with couple other specs start to blow up..

describe "with array as key" do
  it "should create a map function with the composite key" do
    CouchPotato::View::ViewQuery.should_receive(:new).with(anything, anything, anything, string_matching(/emit\(\[doc\['time'\], doc\['state'\]\]/), anything).and_return(stub('view query').as_null_object)
    CouchPotato.database.view Build.key_array_timeline

    CouchPotato.database.save_document Build.new(:state => 'success', :time => Time.now-1000)
    CouchPotato.database.save_document Build.new(:state => 'success', :time => Time.now)

    result = CouchPotato.database.view(Build.timeline(:key => (Time.now-100000)..(Time.now), :descending => true))
    result.length.should > 0
  end
end

railtie_name deprecated in Rails 3 beta 3

$ rake about
(in $HOME/dev/working/d)
DEPRECATION WARNING: railtie_name is deprecated and has no effect. 
                     (called from <class:Railtie> at $HOME/.rvm/gems/ruby-head/gems/couch_potato-0.2.30/lib/couch_potato/railtie.rb:11)
About your application's environment
Ruby version              1.9.2 (i686-linux)
RubyGems version          1.3.6
Rack version              1.1
Rails version             3.0.0.beta3
Active Record version     3.0.0.beta3
Action Pack version       3.0.0.beta3
Active Resource version   3.0.0.beta3
Action Mailer version     3.0.0.beta3
Active Support version    3.0.0.beta3
Middleware                ActionDispatch::Static, Rack::Lock ...
Application root          $HOME/dev/working/fronte
Environment               development

http://github.com/langalex/couch_potato/blob/master/lib/couch_potato/railtie.rb#L11

views not accessible when created on namespaced classes?

This is most probably just me being stupid and not limitation in couch_potato, but still ...

I have two classes each defining a view like this:

class Identity
  view :foo
end

class Identity::Message
  view :bar
end

Now couch_potato uses String#underscore (http://github.com/langalex/couch_potato/blob/master/lib/couch_potato/view/base_view_spec.rb#L11) to generate the design document path resulting in the paths _design/identity and _design/identity/message. This way couch_db can't seem to find the second design doc because it looks for a view defined in the first doc. Or, put differently, maybe couch_db can't know if by _design/identity/message I mean a view defined in _design/identity (like _design/identity/foo) or a different design doc. Does that make any sense?

I worked around this by doing this: http://gist.github.com/346014 but I'm pretty sure there either is something built into couch_potato that I've missed so far or maybe should be.

Anyway. Thanks for any help :)

"eql?" performance issue / rails url helper

I recently noticed some rails url helpers to be exceptionally slow (120ms in some cases) and tracked it down to the use of "eql?" on couch_potato models. For some reason a standard book_path(book) results in a book.eql?(book) call, resulting in 2 to_json calls on the book (which is no problem for other ORM/ODMs).

Is there any reason to do content comparisons there? ActiveRecord, mongoid etc. all do id comparisons only and as there is no test for content equality in couch_potato, I would assume it's not needed here too?

I'll do a pull request later, but wanted to know if there is or was a reason for the content comparison.

Loss of view parameters if view does not exist in db

I am working in a different branch now, but want to move back in the future since the required features are built in the main repo for a large part. I ran into an issue however that might be important:
in the file lib / couch_potato / view / view_query.rb on line 21 query_view parameters is called. If this one fails, an update_view is called followed by a retry. In the first attempt however the parameters are changed and therefore the retry is done with different parameters.

Failing case:
Task.database(Task.by_state(keys: ['active', 'running']))

The keys parameter is removed after the first query_view call. Adding .dup to parameters solves it.

Info:
Ruby 1.9.2p290,
Gems included by the bundle:

  • activemodel (3.2.1)
  • activesupport (3.2.1)
  • archive-tar-minitar (0.5.2)
  • builder (3.0.0)
  • bundler (1.0.21)
  • columnize (0.3.6)
  • couch_potato (0.5.7 3dfc617)
  • couchrest (1.1.2)
  • diff-lcs (1.1.3)
  • i18n (0.6.0)
  • json (1.6.5)
  • linecache19 (0.5.12)
  • mime-types (1.17.2)
  • multi_json (1.0.4)
  • rake (0.9.2.2)
  • rest-client (1.6.7)
  • rspec (2.8.0)
  • rspec-core (2.8.0)
  • rspec-expectations (2.8.0)
  • rspec-mocks (2.8.0)
  • ruby-debug-base19 (0.11.25)
  • ruby-debug19 (0.11.6)
  • ruby_core_source (0.1.5)
  • timecop (0.3.5)
  • tzinfo (0.3.31)

Updating attachment only wont work

When i try to modify a document in CouchDB, just by changing or adding an attachment, this change is not recognized and couch_potato does not send any changes to the database. Only if i modify an additional element, it uploads the changed document including the attachment.

CouchPotato::Config.database_name = 'test'
my_doc = CouchPotato.database.load_document("1")
data = "foo"
my_doc._attachments = {'html' => {'data' => data, 'content_type' => 'text/plain'}}
CouchPotato.database.save_document my_doc

For example my document (my_doc) has no attachment. After using this code, couch_potato wont upload anything, but if i add

my_doc.title = "Foo Title"

before i save the document, couch_potato recognizes a change in the document and uploads my attachment. Normaly it should do this without adding additional elements.
Same if there is an attachment already. Couch_potato needs another element to see that the document changed. "._attachment" only does not work.

update: if i use "is_dirty", it works without additional element

Alternative gem dependency for JRuby: json-jruby rather than json

To allow couch_potato to work within JRuby, please could you add a dependency on the 'json-jruby' gem rather than the 'json' gem if JRUBY_VERSION is non-nil?

I'm afraid I'm not certain of the necessary steps to get this to work with Jeweler and its magical gemspec creation - I modified the Rakefile for my own purposes prior to a 'rake install' but, of course, this won't work for a distributed gem.

support boolean/numeric property types

it should be possible to declare something like property :age, :type => :integer, and then couch potato should convert passed in strings into integers. same with booleans.

Informal schema being enforced by properties

It seems to me that an informal schema is being enforced by the way that properties work on CouchPotato. The issue I see is that when a document is retrieved from the database, it only reconstructs the object based on the properties defined at the class level. So presumably, if you were to ever change the properties on your class, the data stored in the database would no longer work with your application.

Here is an example...

# Define a person
class Person
  include CouchPotato::Persistence
  property :name
end

p = Person.new(:name => "Bill Lumbergh")
=> #<Person:0x2193c58 @name="Bill Lumbergh", @created_at_was=nil, @updated_at_was=nil, @name_was="Bill Lumbergh">

CouchPotato.database.save_document p
=> true

p.id
=> "21bd46de161ddbbb81eb5a49b9bf513d"


# Redefine person and reload app
class Person
  include CouchPotato::Persistence
  property :first_name
  property :last_name
end

p = CouchPotato.database.load_document "21bd46de161ddbbb81eb5a49b9bf513d"
=> #<Person:0x29ee830 @created_at_was=2009-06-03 14:54:26 UTC, @updated_at_was=2009-06-03 14:54:26 UTC, @first_name_was=nil, @last_name_was=nil, @_id="21bd46de161ddbbb81eb5a49b9bf513d", @_rev="1-1181420853", @created_at=2009-06-03 14:54:26 UTC, @updated_at=2009-06-03 14:54:26 UTC, @first_name=nil, @last_name=nil>

p.name
NoMethodError: undefined method `name' for #<Person:0x29ee830>
  from (irb):11
  from /opt/local/bin/irb:12:in `<main>'

This seems to be not in the spirit of a schemaless database. There should be enough data in the json to reconstruct the object instead of using the properties defined on the class.

I believe that CouchRest handles this by having all persistable objects extend hash, so it takes on more of a dynamic nature. So even if a name property is not defined by the class, something like this is totally valid:

person['name'] = "Bill"

I am trying to think of a good way to re-implement properties to allow for this behavior. If you have any opinion, please let me know.

Peter

Dynamic conditions in views

Sorry for n00bish question, but I'd like to pass dynamic values to views via view definition in model. Something like:

view :completed, :key => :name, :conditions => "doc.completed === #{var}"

Is it at all possible, or should I stick with filters I wrote in JS?

Loaded Documents Aren't Typecasted to its Parent Class

I am not sure what I am doing wrong, but when I load a document via an ID, the returned object is a CouchRest::Document instead of the class specified in the ruby_class attribute. All of the data is correctly there, but it's essentially just a hash. The README says just merely loading the document should typecast back to its parent class.

I'm using:
couchrest 1.0.0
couch_potato 0.3.0
json 1.2.4 & 1.4.6

Can we have a way of overriding the 'ruby_class' thing?

Hey,

I'd like to use couch_potato to integrate with an existing CouchDB system. We already have a standard naming for the 'type' of each document (we're using doctype). I don't want to have 'doctype' as well as 'ruby_class' in every document.

Would it be possible to make the string used configurable, while defaulting to 'ruby_class'? It would make couch_potato much more suitable for integrating with existing couchdb systems.

Cheers

Database sytnax

I'm not too crazy about the syntax of dealing with the database. To me it seems a bit cumbersome to need to manually get an instance of a database everytime you want to do something with a model.

I understand the advantages, it just seems like a case of letting testing considerations define the api. Possibly, I'm not to convinced either that models exist long enough in a typical stateless web app to really be weighed down. If you compare your couchrest sample wiki to the the couchpotato one, it seems like a lot of extra code to do the same thing.

So one idea... since the model is already decoupled from the database, would it make sense to have the save method on the model be responsible for getting an instance of the database right before save, and have it do something like db.save(self). Then loose the reference to the database when it's done.

That way, testing remains decoupled, but we don't have so much of the PHP reminiscent syntax. I know I am probably being picky here, but the model.save idiom in the ruby world is so beloved, I think it may be hard to deviate so much. I may be wrong however.

require 'couch_potato/rspec' => "cannot load such file -- rspec/matchers"

require 'couch_potato/rspec'

raises

/Users/andrewen/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/couch_potato-0.7.0.pre.1/lib/couch_potato/rspec/matchers.rb:22:in `<module:RSpec>': cannot load such file -- rspec/matchers (LoadError)
from /Users/andrewen/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/couch_potato-0.7.0.pre.1/lib/couch_potato/rspec/matchers.rb:21:in `<top (required)>'

The output of bundle show is:

  • activemodel (3.2.3)
  • activesupport (3.2.3)
  • addressable (2.2.7)
  • builder (3.0.0)
  • bundler (1.1.4)
  • capybara (1.1.2)
  • childprocess (0.3.2)
  • couch_potato (0.6.0)
  • couchrest (1.0.1)
  • cucumber (1.1.9)
  • daemons (1.1.8)
  • diff-lcs (1.1.3)
  • eventmachine (0.12.10)
  • fakeweb (1.3.0)
  • ffi (1.0.11)
  • gherkin (2.9.3)
  • i18n (0.6.0)
  • json (1.6.6)
  • launchy (2.1.0)
  • libwebsocket (0.1.3)
  • mime-types (1.18)
  • multi_json (1.3.2)
  • nokogiri (1.5.2)
  • oauth (0.4.6)
  • rack (1.4.1)
  • rack-protection (1.2.0)
  • rack-test (0.6.1)
  • rake (0.9.2.2)
  • rest-client (1.6.7)
  • rspec (2.9.0)
  • rspec-core (2.9.0)
  • rspec-expectations (2.9.1)
  • rspec-mocks (2.9.0)
  • rubyzip (0.9.7)
  • selenium-webdriver (2.21.2)
  • sinatra (1.3.2)
  • term-ansicolor (1.0.7)
  • thin (1.3.1)
  • tilt (1.3.3)
  • timecop (0.3.5)
  • twitter_oauth (0.4.3)
  • validatable (1.6.7)
  • xpath (0.1.4)

I haven't tried with HEAD though. If you need anything else to reproduce this, let me know.

problem with is_dirty method

i want to write a migration where i just try to force save documents to the database, so that defaults, that i intruduced at some point get updated in the documents.

when i try to update my user model user.is_dirty; user.save! i get an NoMethodError: undefined method 'email_changed?' for #<User:0x007fb223c1d478> error.

this seems to come from simple_property.rb and looks like a validation-callback from active-model:

  def dirty?(object)
    object.send("#{name}_changed?")
  end

i really did not understand how this should be working. are there some magic helper methods generated somewhere that should provide methods like email_changed? for all my model classes?

on the other hand if i update the e-mail property everything works fine:

1.9.3-p0 :011 > user.email = '[email protected]'; user.save!
 => true 

here is the stack:

1.9.3-p0 :009 > u.is_dirty;u.save!
NoMethodError: undefined method `email_changed?' for #<User:0x007fb223c1d478>
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/ghost_attributes.rb:7:in `method_missing'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/dirty_attributes.rb:32:in `method_missing'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in `method_missing'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:446:in `_run_validate_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:212:in `run_validations!'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:179:in `valid?'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:174:in `valid_document?'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:157:in `block (2 levels) in update_document'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_update_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:156:in `block in update_document'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_save_callbacks'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:155:in `update_document'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:81:in `save_document'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:88:in `save_document!'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:120:in `block in save!'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:102:in `block in with_database'
    from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato.rb:44:in `with_database'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:101:in `with_database'
    from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:119:in `save!'
    from (irb):9
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from scri = User.last
 => #<User _id: "c1ce28d993958de695f8fe45a0181aed", _rev: "14-dc2d20691289523ab02f7b51be75a6ce", created_at: Wed, 15 Feb 2012 15:41:19 CET +01:00, updated_at: Thu, 16 Feb 2012 10:54:48 CET +01:00, email: "[email protected]", encrypted_password: "$2a$10$BaM29xYH/JPMuf82orRrVOR1uql/tpKj/4HTpkshTd/6B3NJCmaym", authentication_token: nil, remember_created_at: nil, reset_password_token: nil, reset_password_sent_at: nil, confirmation_token: nil, confirmed_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, confirmation_sent_at: Wed, 15 Feb 2012 15:41:19 CET +01:00, failed_attempts: nil, unlock_token: nil, locked_at: nil, sign_in_count: 1, current_sign_in_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, last_sign_in_at: Wed, 15 Feb 2012 15:43:00 CET +01:00, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", first_name: "uschi", last_name: "müller", disable_mailings: nil, one_click_token: "8FvxZPqakU9F4JQQLEPY", salutation_code: "mr", password: nil, last_terms_of_use_check: Tue, 20 Dec 2011, site_code: "DE"> 
1.9.3-p0 :011 > u.email = 'uschi@muschiiiii.de';u.save!
 => true 

ruby_class attribute in every document

Hi,
couchdb document have attribute "ruby_class" in every and each document ..
while every database have and represent one model document

as in blog example the database represent model "Post" which have the attribute "comments" represent Comment Model .. why adding "ruby_class" in every Post and every Comment.

type_caster.rb uses #blank?

I'm using couch_potato with a Sinatra app and started by creating a new rvm gemset with only my project's dependencies. When I use CouchPotato, I get an exception in type_caster.rb, around line 31, complaining the method "blank?" doesn't exist.

AFAIK, #blank? is defined by ActiveSupport, which is not installed as a dependency for CouchPotato by default. Is it an omission in the Jeweler task or should it be changed in the codebase?

Readme.md typo

Section: "Create a config/couchdb.yml:"
Line: default_language = :erlang # optional
Should be: default_language: :erlang # optional

Regards
Robert

undefined class/module error on load_document

I
set up a model (User) with a simple CRUD controller and am trying to
get the basic CRUD functionality to work. The problem I had was that
attempting to load a User document form couchDB with this code

user_document = CouchPotato.database.load_document params[:id]

resulted in the following error

undefined class/module User

...

When I dropped a breakpoint where the error was happened and
instantiated a new User in the debugger and then continued the
document was returned as expected. It seems that the User class is
lazy loaded and is not available when the json parser needs it. The
hacky fix is to instantiate a new user before the load_document call.
Is there a better way to deal with this?

Can property be a list of any object?

I see how, as long as the object implementes json_create and to_json, we can use it as a type of property.

What's the simplest way to have a property be a list of a particular type without implementing a boilerplate "ListofMyObject" class?

Thanks for any help.

M

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.