Skip to content

Commit

Permalink
oops forgot to undo this fubar optimization on the mongo side
Browse files Browse the repository at this point in the history
  • Loading branch information
rsl committed Dec 6, 2012
1 parent dd3bf0a commit 3d8004e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/acts_as_url/adapter/mongoid.rb
Expand Up @@ -16,4 +16,78 @@ class Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title
end

class Updatument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :sync_url => true
end

class Mocument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :scope => :other, :sync_url => true
end

class Permument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :url_attribute => :permalink
end

class Procument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :non_attribute_method

def non_attribute_method
"#{title} got massaged"
end
end

class Blankument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :only_when_blank => true
end

class Duplicatument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :duplicate_count_separator => "---"
end

class Validatument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :sync_url => true
validates_presence_of :title
end

class Ununiqument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :allow_duplicates => true
end

class Limitument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self

acts_as_url :title, :limit => 13
end

class Skipument
include Mongoid::Document
Stringex::ActsAsUrl.mix_into self
acts_as_url :title, :exclude => ["_So_Fucking_Special"]
end

2 comments on commit 3d8004e

@kristianmandrup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out my code at https://github.com/kristianmandrup/stringex/blob/master/test_mongoid/acts_as_url_mongoid_test.rb

Start the mongoid database

$ mongod

require 'mongoid'
require 'moped'

Mongoid.configure do |config|
  config.connect_to('acts_as_url')  
end

All there is to it!

class Document 
  include Mongoid::Document
  field :title, type: String

  acts_as_url :title
end

I don't see why adding acts_as_url directly to Mongoid::Document as a class method that in turn also includes Stringex::ActsAsUrl is such a bad idea? This is very common practice in the Mongoid world, especially with this kind of gem, where you would expect, that if you include and use this gem, you pretty much want to use the "url as name" strategy for most if not all of your models...

Just the way I see it and how I would use it. Check out any gem that supports Mongoid and you will quickly see how to setup the test suite.

BTW: Doesn't almost everybody use rspec by now? The test-unit (and family) looks so ancient to me.... so old school 2005 (and before) IMO, closely mirroring on Unit Tests for Java. But hey, do whatever you feel comfortable and productive with ;)
Why use rake test at all?

@rsl
Copy link
Owner Author

@rsl rsl commented on 3d8004e Dec 7, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

including ActsAsUrl isn't as easy with Mongoid [or Datamapper, i'm guessing] because of this: https://gist.github.com/9f1e652a8199376c1859 when you include a class/module that has extensions/inclusions, those methods don't show up on the newest object. i can hack around with aliasing to get include Mongoid::Document to reinclude the Stringex features easy enough but i wasn't sure how magic-friendly Mongoid users are. with all the data definitions in the models, i figured there's a non-zero chance that those users may want to have to manually include things or something. but since you mentioned it as a weird thing, that confirms my impulse to just make it work for the end user without them having to get so involved.

using rspec adds another dependency. that's why i never use it on oss stuff. what's fubar is that add_development_dependency adds regular dependencies for any gem version under 1.2.0 basically, which includes lot of ppl. i hate unnecessary dependencies so i just use test::unit because it's in the standard lib. i used to prefer rspec but now tbh it doesn't matter. there's little you can do with one testing framework that you can't do in another [with perhaps more work]. tools are tools.

Please sign in to comment.