Permalink
Browse files

I accidentally the whole remarkable_activerecord

  • Loading branch information...
0 parents commit f907eca955374adf5739ea5504e1fb7946102191 @reinh committed Jan 5, 2011
Showing with 5,647 additions and 0 deletions.
  1. +147 −0 CHANGELOG
  2. +20 −0 LICENSE
  3. +87 −0 README
  4. +30 −0 Rakefile
  5. +30 −0 lib/remarkable_activerecord.rb
  6. +252 −0 lib/remarkable_activerecord/base.rb
  7. +198 −0 lib/remarkable_activerecord/describe.rb
  8. +37 −0 lib/remarkable_activerecord/human_names.rb
  9. +138 −0 lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb
  10. +66 −0 lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb
  11. +88 −0 lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb
  12. +283 −0 lib/remarkable_activerecord/matchers/association_matcher.rb
  13. +68 −0 lib/remarkable_activerecord/matchers/have_column_matcher.rb
  14. +69 −0 lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb
  15. +73 −0 lib/remarkable_activerecord/matchers/have_index_matcher.rb
  16. +30 −0 lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb
  17. +85 −0 lib/remarkable_activerecord/matchers/have_scope_matcher.rb
  18. +50 −0 lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb
  19. +103 −0 lib/remarkable_activerecord/matchers/validate_associated_matcher.rb
  20. +44 −0 lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb
  21. +57 −0 lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb
  22. +57 −0 lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb
  23. +150 −0 lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb
  24. +188 −0 lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb
  25. +91 −0 lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb
  26. +233 −0 lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb
  27. +264 −0 locale/en.yml
  28. +35 −0 remarkable_activerecord.gemspec
  29. +130 −0 spec/accept_nested_attributes_for_matcher_spec.rb
  30. +114 −0 spec/allow_mass_assignment_of_matcher_spec.rb
  31. +80 −0 spec/allow_values_for_matcher_spec.rb
  32. +671 −0 spec/association_matcher_spec.rb
  33. +100 −0 spec/describe_spec.rb
  34. +78 −0 spec/have_column_matcher_spec.rb
  35. +52 −0 spec/have_default_scope_matcher_spec.rb
  36. +87 −0 spec/have_index_matcher_spec.rb
  37. +47 −0 spec/have_readonly_attributes_matcher_spec.rb
  38. +85 −0 spec/have_scope_matcher_spec.rb
  39. +101 −0 spec/model_builder.rb
  40. +2 −0 spec/rcov.opts
  41. +4 −0 spec/spec.opts
  42. +27 −0 spec/spec_helper.rb
  43. +68 −0 spec/validate_acceptance_of_matcher_spec.rb
  44. +126 −0 spec/validate_associated_matcher_spec.rb
  45. +58 −0 spec/validate_confirmation_of_matcher_spec.rb
  46. +87 −0 spec/validate_exclusion_of_matcher_spec.rb
  47. +87 −0 spec/validate_inclusion_of_matcher_spec.rb
  48. +218 −0 spec/validate_length_of_matcher_spec.rb
  49. +186 −0 spec/validate_numericality_of_matcher_spec.rb
  50. +84 −0 spec/validate_presence_of_matcher_spec.rb
  51. +182 −0 spec/validate_uniqueness_of_matcher_spec.rb
@@ -0,0 +1,147 @@
+* allow_values_for checks for any message unless otherwise given [#90]
+
+* Allow booleans to be given to validate_inclusion_of [#89]
+
+* Allow allow_values_for and allow_mass_assignment_of matchers to be executed in
+ the negative form by including Remarkable::Negative module [#85]
+
+* Ensure quick subject bypass protected attributes [#87]
+
+* Added :token and :separator to deal with :tokenizer in validates_length_of [#77]
+
+* Deprecated validate_format_of. It does not have the same API as the respective
+ ActiveRecord macro, raising questions frequentely about its usage [#76]
+
+* allow_mass_assignment_of when called without arguments checks if any mass
+ assignment is possible [#80]
+
+* Add :table_name option to have_index (thanks to Lawrence Pit) [#79]
+
+* Allow default subject attributes to be given [#74]
+ You can even mix with a fixture replacement tool and still use quick subjects:
+
+ describe Post
+ # Fixjour example
+ subject_attributes { valid_post_attributes }
+
+ describe :published => true do
+ should_validate_presence_of :published_at
+ end
+ end
+
+* Bug fix when a symbol is given has join table to habtm association [#75]
+
+* Association matchers now searches in the right database for tables [#73]
+
+* validate_length_of accepts :with_kind_of to enable it to work with associations [#69]
+ In your Post specs now you can write:
+
+ should_validate_length_of :comments, :maximum => 10, :with_kind_of => Comment
+
+# v3.1
+
+* Allow validate_presence_of to work with associations [#63]
+
+* Allow validate_uniqueness_of to work when scopes are not stringfiable values.
+ You can now give timestamps, datetime, date and boolean as scopes [#60]
+
+* Allow subjects to be overwriten quickly (quick subjects):
+
+ describe Post
+ should_validate_presente_of :title
+
+ describe :published => true do
+ should_validate_presence_of :published_at
+ end
+ end
+
+ Is the same as:
+
+ describe Post
+ should_validate_presente_of :title
+
+ describe "when published is true" do
+ subject { Post.new(:published => true) }
+ should_validate_presence_of :published_at
+ end
+ end
+
+ And the string can be also localized using I18n [#57]
+
+[COMPATIBILITY] validate_associated no longer accepts a block to confgure the
+builder:
+
+ should_validate_associated(:tasks){ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
+
+The right way to do this is by giving an option called builder and a proc:
+
+ should_validate_associated :tasks, :builder => proc{ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
+
+* validate_uniqueness_of and accept_nested_attributes_for now use the new
+ interpolation option {{sentence}} [#58]
+
+* Added accept_nested_attributes_for matcher [#39]
+
+* Added have_default_scope matcher [#38]
+
+* Allow :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly,
+ :group, :having, :from, :lock as quick accessors to have_scope matcher
+
+* Allow all kind of objects to be sent to have_scope (including datetimes, arrays,
+ booleans and nil) (thanks to Szymon Nowak and Nolan Eakins) [#53]
+
+* Added support to sql options in association_matcher: select, conditions, include,
+ group, having, order, limit and offset, plus finder_sql and counter_sql. [#48]
+
+* :source and :source_type are now supported by association matcher [#47]
+
+* validate_inclusion_of became smarter since it now tests invalid values too [#36]
+
+* Fixed three bugs in validate_uniqueness_of matcher [#42] [#40] [#37]
+
+# v3.0
+
+* Added more options to associations matcher. Previously it was handling just
+:dependent and :through options. Now it deals with:
+
+ :through, :class_name, :foreign_key, :dependent, :join_table, :uniq,
+ :readonly, :validate, :autosave, :counter_cache, :polymorphic
+
+And they are much smarter! In :join_table and :through cases, they also test if
+the table exists or not. :counter_cache and :foreign_key also checks if the
+column exists or not.
+
+[COMPATIBILITY] Removed callback, have_instance_method and have_class_method
+matchers. They don't lead to a good TDD since you should test they behavior
+and not wether they exist or not.
+
+[COMPATIBILITY] ActiveRecord matches does not pick the instance variable from
+the spec environment. So we should target only rspec versions that supports
+subjects (>= 1.1.12).
+
+Previously, when we are doing this:
+
+ describe Product
+ before(:each){ @product = Product.new(:tangible => true) }
+ should_validate_presence_of :size
+ end
+
+It was validating the @product instance variable. However this might be not
+clear. The right way to do that (with subjects) is:
+
+ describe Product
+ subject{ Product.new(:tangible => true) }
+ should_validate_presence_of :size
+ end
+
+Is also valid to remember that previous versions of Remarkable were overriding
+subject definitions on rspec. This was also fixed.
+
+# v2.x
+
+* Added associations, allow_mass_assignment, allow_values_for, have_column,
+have_index, have_scope, have_readonly_attributes, validate_acceptance_of,
+validate_associated, validate_confirmation_of, validate_exclusion_of,
+validate_inclusion_of, validate_length_of, validate_numericality_of,
+validate_presence_of and validate_uniqueness_of matchers.
+
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Carlos Brando
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
+= Remarkable ActiveRecord
+
+Remarkable ActiveRecord is a collection of matchers to ActiveRecord. Why use
+Remarkable?
+
+* Matchers for all ActiveRecord validations, with support to all options. The only
+ exceptions are validate_format_of (which should be invoked as allow_values_for)
+ and the :on option;
+
+* Matchers for all ActiveRecord associations. The only one which supports all
+ these options:
+
+ :through, :source, :source_type, :class_name, :foreign_key, :dependent,
+ :join_table, :uniq, :readonly, :validate, :autosave, :counter_cache, :polymorphic
+
+ Plus SQL options:
+
+ :select, :conditions, :include, :group, :having, :order, :limit, :offset
+
+ Besides in Remarkable 3.0 matchers became much smarter. Whenever :join_table
+ or :through is given as option, it checks if the given table exists. Whenever
+ :foreign_key or :counter_cache is given, it checks if the given column exists;
+
+* Tests and more tests. We have a huge tests suite ready to run and tested in
+ ActiveRecord 2.1.2, 2.2.2 and 2.3.2;
+
+* Great documentation;
+
+* I18n.
+
+== Examples
+
+All Remarkable macros can be accessed in two different ways. For those who prefer the Shoulda style, let’s look at some model tests:
+
+ describe Post do
+ should_belong_to :user
+ should_have_many :comments
+ should_have_and_belong_to_many :tags
+
+ should_validate_presence_of :body
+ should_validate_presence_of :title
+ should_validate_uniqueness_of :title, :allow_blank => true
+ end
+
+For those who likes more the Rspec way can simply do:
+
+ describe Post do
+ it { should belong_to(:user) }
+ it { should have_many(:comments) }
+ it { should have_and_belong_to_many(:tags) }
+
+ it { should validate_presence_of(:body) }
+ it { should validate_presence_of(:title) }
+ it { should validate_uniqueness_of(:title, :allow_blank => true) }
+ end
+
+== I18n
+
+All matchers come with I18n support. If you want to translate your matchers,
+grab make a copy of locale/en.yml and start to translate it.
+
+Then add your new locale file to Remarkable:
+
+ Remarkable.add_locale 'path/to/my_locale.yml'
+
+And then:
+
+ Remarkable.locale = :my_locale
+
+== Using it outside Rails
+
+If you want to use Remarkable ActiveRecord outside Rails, you have to remember
+a few things:
+
+ 1. Internationalization is powered by the I18n gem. If you are using it with Rails,
+ it will use the built in gem, otherwise you will have to install the gem by hand:
+
+ gem sources -a http://gems.github.com
+ sudo gem install svenfuchs-i18n
+
+ 2. Include the matchers. Remarkable Rails gem is the responsable to add
+ ActiveRecord matchers to rspec. If you are not using it, you have to do:
+
+ Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
+
+ This will make ActiveRecord matchers available in all rspec example groups.
+
@@ -0,0 +1,30 @@
+# encoding: utf-8
+PROJECT_SUMMARY = "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
+PROJECT_DESCRIPTION = PROJECT_SUMMARY
+
+GEM_NAME = "remarkable_activerecord"
+GEM_AUTHOR = [ "Carlos Brando", "José Valim", "Diego Carrion" ]
+GEM_EMAIL = [ "eduardobrando@gmail.com", "jose.valim@gmail.com", "dc.rec1@gmail.com" ]
+
+EXTRA_RDOC_FILES = ["README", "LICENSE", "CHANGELOG"]
+
+require File.join(File.dirname(__FILE__), "..", "rake_helpers.rb")
+
+########### Package && release
+
+configure_gemspec! do |s|
+ s.add_dependency('remarkable', "~> #{GEM_VERSION}")
+end
+
+########### Specs
+
+RAILS_VERSIONS = ['2.2.2', '2.3.4', '2.3.5']
+
+desc "Run the specs under spec with supported Rails versions"
+task :pre_commit do
+ RAILS_VERSIONS.each do |version|
+ ENV['RAILS_VERSION'] = version
+ puts "\n=> #{GEM_NAME}: rake spec RAILS_VERSION=#{version}"
+ Rake::Task[:spec].execute
+ end
+end
@@ -0,0 +1,30 @@
+# Load Remarkable
+unless Object.const_defined?('Remarkable')
+ begin
+ require 'remarkable'
+ rescue LoadError
+ require 'rubygems'
+ gem 'remarkable'
+ require 'remarkable'
+ end
+end
+
+# Load Remarkable ActiveRecord files
+dir = File.dirname(__FILE__)
+require File.join(dir, 'remarkable_activerecord', 'base')
+require File.join(dir, 'remarkable_activerecord', 'describe')
+require File.join(dir, 'remarkable_activerecord', 'human_names')
+
+# Add locale
+Remarkable.add_locale File.join(dir, '..', 'locale', 'en.yml')
+
+# Add matchers
+Dir[File.join(dir, 'remarkable_activerecord', 'matchers', '*.rb')].each do |file|
+ require file
+end
+
+# By default, ActiveRecord matchers are not included in any example group.
+# The responsable for this is RemarkableRails. If you are using ActiveRecord
+# without Rails, put the line below in your spec_helper to include ActiveRecord
+# matchers into rspec globally.
+# Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
Oops, something went wrong.

0 comments on commit f907eca

Please sign in to comment.