Permalink
Browse files

Merge branch 'rspec_suite'

  • Loading branch information...
cheald committed Jul 3, 2013
2 parents 61aa557 + 0fa179f commit 46992503b502f432309652bb55788673087327b4
Showing with 13,698 additions and 65 deletions.
  1. +2 −14 Gemfile
  2. +9 −6 Rakefile
  3. +15 −0 gemfiles/Gemfile.common
  4. +2 −14 gemfiles/rails3_0.gemfile
  5. +2 −14 gemfiles/rails3_1.gemfile
  6. +2 −14 gemfiles/rails3_2.gemfile
  7. +21 −0 lib/mongo_mapper/extensions/ordered_hash.rb
  8. +6 −3 lib/mongo_mapper/plugins/keys.rb
  9. +198 −0 spec/functional/accessible_spec.rb
  10. +64 −0 spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb
  11. +236 −0 spec/functional/associations/belongs_to_proxy_spec.rb
  12. +349 −0 spec/functional/associations/in_array_proxy_spec.rb
  13. +230 −0 spec/functional/associations/many_documents_as_proxy_spec.rb
  14. +893 −0 spec/functional/associations/many_documents_proxy_spec.rb
  15. +238 −0 spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb
  16. +288 −0 spec/functional/associations/many_embedded_proxy_spec.rb
  17. +302 −0 spec/functional/associations/many_polymorphic_proxy_spec.rb
  18. +489 −0 spec/functional/associations/one_as_proxy_spec.rb
  19. +207 −0 spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb
  20. +100 −0 spec/functional/associations/one_embedded_proxy_spec.rb
  21. +382 −0 spec/functional/associations/one_proxy_spec.rb
  22. +48 −0 spec/functional/associations_spec.rb
  23. +27 −0 spec/functional/binary_spec.rb
  24. +75 −0 spec/functional/caching_spec.rb
  25. +232 −0 spec/functional/callbacks_spec.rb
  26. +306 −0 spec/functional/dirty_spec.rb
  27. +282 −0 spec/functional/document_spec.rb
  28. +75 −0 spec/functional/dynamic_querying_spec.rb
  29. +288 −0 spec/functional/embedded_document_spec.rb
  30. +20 −0 spec/functional/equality_spec.rb
  31. +458 −0 spec/functional/identity_map_spec.rb
  32. +48 −0 spec/functional/indexes_spec.rb
  33. +20 −0 spec/functional/logger_spec.rb
  34. +551 −0 spec/functional/modifiers_spec.rb
  35. +89 −0 spec/functional/pagination_spec.rb
  36. +199 −0 spec/functional/protected_spec.rb
  37. +960 −0 spec/functional/querying_spec.rb
  38. +34 −0 spec/functional/rails_spec.rb
  39. +144 −0 spec/functional/safe_spec.rb
  40. +280 −0 spec/functional/sci_spec.rb
  41. +171 −0 spec/functional/scopes_spec.rb
  42. +97 −0 spec/functional/timestamps_spec.rb
  43. +125 −0 spec/functional/touch_spec.rb
  44. +46 −0 spec/functional/userstamps_spec.rb
  45. +414 −0 spec/functional/validations_spec.rb
  46. +58 −0 spec/spec_helper.rb
  47. +21 −0 spec/support/matchers.rb
  48. +261 −0 spec/support/models.rb
  49. +146 −0 spec/unit/associations/base_spec.rb
  50. +30 −0 spec/unit/associations/belongs_to_association_spec.rb
  51. +64 −0 spec/unit/associations/many_association_spec.rb
  52. +48 −0 spec/unit/associations/one_association_spec.rb
  53. +100 −0 spec/unit/associations/proxy_spec.rb
  54. +74 −0 spec/unit/clone_spec.rb
  55. +22 −0 spec/unit/config_generator_spec.rb
  56. +249 −0 spec/unit/document_spec.rb
  57. +125 −0 spec/unit/dynamic_finder_spec.rb
  58. +676 −0 spec/unit/embedded_document_spec.rb
  59. +38 −0 spec/unit/equality_spec.rb
  60. +12 −0 spec/unit/exceptions_spec.rb
  61. +380 −0 spec/unit/extensions_spec.rb
  62. +134 −0 spec/unit/identity_map_middleware_spec.rb
  63. +47 −0 spec/unit/inspect_spec.rb
  64. +223 −0 spec/unit/key_spec.rb
  65. +89 −0 spec/unit/keys_spec.rb
  66. +43 −0 spec/unit/model_generator_spec.rb
  67. +175 −0 spec/unit/mongo_mapper_spec.rb
  68. +11 −0 spec/unit/pagination_spec.rb
  69. +89 −0 spec/unit/plugins_spec.rb
  70. +40 −0 spec/unit/rails_compatibility_spec.rb
  71. +118 −0 spec/unit/rails_reflect_on_association_spec.rb
  72. +183 −0 spec/unit/rails_spec.rb
  73. +169 −0 spec/unit/serialization_spec.rb
  74. +218 −0 spec/unit/serializers/json_serializer_spec.rb
  75. +198 −0 spec/unit/serializers/xml_serializer_spec.rb
  76. +44 −0 spec/unit/time_zones_spec.rb
  77. +27 −0 spec/unit/translation_spec.rb
  78. +562 −0 spec/unit/validations_spec.rb
16 Gemfile
@@ -1,16 +1,4 @@
source 'https://rubygems.org'
eval File.read(File.expand_path('../gemfiles/Gemfile.common', __FILE__)), nil, 'Gemfile.common'
gemspec

gem 'rake'
gem 'mongo', '~> 1.8'
gem 'bson_ext', '~> 1.8'
gem 'multi_json', '~> 1.2.0'

group :test do
gem 'rails', '~> 3.2.0'
gem 'jnunemaker-matchy', '~> 0.4', :require => 'matchy'
gem 'shoulda', '~> 2.11'
gem 'timecop', '~> 0.3'
gem 'mocha', '~> 0.10.0'
gem 'rack-test', '~> 0.6'
end
gem 'rails', '~> 3.2.0', :group => :test
@@ -1,16 +1,19 @@
require 'rubygems'
require 'bundler/setup'
require 'rake'
require 'rake/testtask'
require File.expand_path('../lib/mongo_mapper/version', __FILE__)

Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rspec_opts = ['--color']
end
task :default => :spec
rescue LoadError
nil
end

task :default => :test

desc 'Builds the gem'
task :build do
sh "gem build mongo_mapper.gemspec"
@@ -0,0 +1,15 @@
source 'https://rubygems.org'

gem 'rake'
gem 'mongo', '~> 1.8.0'
gem 'multi_json', '~> 1.2.0'

platforms :ruby do
gem 'bson_ext', '~> 1.8.0'
end

group :test do
gem 'rspec'
gem 'timecop', '~> 0.3'
gem 'rack-test', '~> 0.5'
end
@@ -1,16 +1,4 @@
source 'https://rubygems.org'
eval File.read(File.expand_path('../Gemfile.common', __FILE__)), nil, 'Gemfile.common'
gemspec :path => '../'

gem 'rake'
gem 'mongo', '~> 1.8'
gem 'bson_ext', '~> 1.8'
gem 'multi_json', '~> 1.2.0'

group :test do
gem 'rails', '~> 3.0.0'
gem 'jnunemaker-matchy', '~> 0.4', :require => 'matchy'
gem 'shoulda', '~> 2.11'
gem 'timecop', '~> 0.3'
gem 'mocha', '~> 0.10.0'
gem 'rack-test', '~> 0.6'
end
gem 'rails', '~> 3.0.0', :group => :test
@@ -1,16 +1,4 @@
source 'https://rubygems.org'
eval File.read(File.expand_path('../Gemfile.common', __FILE__)), nil, 'Gemfile.common'
gemspec :path => '../'

gem 'rake'
gem 'mongo', '~> 1.8'
gem 'bson_ext', '~> 1.8'
gem 'multi_json', '~> 1.2.0'

group :test do
gem 'rails', '~> 3.1.0'
gem 'jnunemaker-matchy', '~> 0.4', :require => 'matchy'
gem 'shoulda', '~> 2.11'
gem 'timecop', '~> 0.3'
gem 'mocha', '~> 0.10.0'
gem 'rack-test', '~> 0.6'
end
gem 'rails', '~> 3.1.0', :group => :test
@@ -1,16 +1,4 @@
source 'https://rubygems.org'
eval File.read(File.expand_path('../Gemfile.common', __FILE__)), nil, 'Gemfile.common'
gemspec :path => '../'

gem 'rake'
gem 'mongo', '~> 1.8'
gem 'bson_ext', '~> 1.8'
gem 'multi_json', '~> 1.2.0'

group :test do
gem 'rails', '~> 3.2.0'
gem 'jnunemaker-matchy', '~> 0.4', :require => 'matchy'
gem 'shoulda', '~> 2.11'
gem 'timecop', '~> 0.3'
gem 'mocha', '~> 0.10.0'
gem 'rack-test', '~> 0.6'
end
gem 'rails', '~> 3.2.0', :group => :test
@@ -0,0 +1,21 @@
# encoding: UTF-8
# This class exists to make sure that Hash's extensions don't end up giving us unordered hashes.
if RUBY_VERSION < "1.9"
module MongoMapper
module Extensions
module OrderedHash
def to_mongo(value)
value
end

def from_mongo(value)
value
end
end
end
end

class BSON::OrderedHash
extend MongoMapper::Extensions::OrderedHash
end
end
@@ -194,8 +194,8 @@ def attributes=(attrs)
end
end

def attributes
HashWithIndifferentAccess.new.tap do |attrs|
def to_mongo
BSON::OrderedHash.new.tap do |attrs|
keys.each do |name, key|
if key.type == ObjectId || !self[key.name].nil?
value = key.set(self[key.name])
@@ -214,7 +214,10 @@ def attributes
end
end
end
alias :to_mongo :attributes

def attributes
to_mongo.with_indifferent_access
end

def assign(attrs={})
warn "[DEPRECATION] #assign is deprecated, use #attributes="
@@ -0,0 +1,198 @@
require 'spec_helper'

describe "Accessible" do
context 'A document with accessible attributes' do
before do
@doc_class = Doc do
key :name, String
key :admin, Boolean, :default => false

attr_accessible :name
end

@doc = @doc_class.create(:name => 'Steve Sloan')
end

it 'should have accessible attributes class method' do
@doc_class.accessible_attributes.should == [:name].to_set
end

it "should default accessible attributes to nil" do
Doc().accessible_attributes.should be_nil
end

it "should have accessible_attributes instance method" do
@doc.accessible_attributes.should equal(@doc_class.accessible_attributes)
end

it "should raise error if there are protected attributes" do
doc = Doc('Post')
doc.attr_protected :admin
lambda { doc.attr_accessible :name }.
should raise_error(/Declare either attr_protected or attr_accessible for Post/)
end

it "should know if using accessible attributes" do
@doc_class.accessible_attributes?.should be(true)
Doc().accessible_attributes?.should be(false)
end

it "should assign inaccessible attribute through accessor" do
@doc.admin = true
@doc.admin.should be_true
end

it "should ignore inaccessible attribute on #initialize" do
doc = @doc_class.new(:name => 'John', :admin => true)
doc.admin.should be_false
doc.name.should == 'John'
end

it "should not ignore inaccessible attributes on #initialize from the database" do
doc = @doc_class.new(:name => 'John')
doc.admin = true
doc.save!

doc = @doc_class.first(:name => 'John')
doc.admin.should be_true
doc.name.should == 'John'
end

it "should not ignore inaccessible attributes on #reload" do
doc = @doc_class.new(:name => 'John')
doc.admin = true
doc.save!

doc.reload
doc.admin.should be_true
doc.name.should == 'John'
end

it "should not ignore inaccessible attribute on #update_attribute" do
@doc.update_attribute('admin', true)
@doc.admin.should be_true
end

it "should ignore inaccessible attribute on #update_attributes" do
@doc.update_attributes(:name => 'Ren Hoek', :admin => true)
@doc.name.should == 'Ren Hoek'
@doc.admin.should be_false
end

it "should ignore inaccessible attribute on #update_attributes!" do
@doc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
@doc.name.should == 'Stimpson J. Cat'
@doc.admin.should be_false
end

it "should ignore inaccessible attribute on #attributes=" do
@doc.attributes = {:name => 'Ren Hoek', :admin => true}
@doc.name.should == 'Ren Hoek'
@doc.admin.should be_false
end

it "should be indifferent to whether the accessible keys are strings or symbols" do
@doc.update_attributes!("name" => 'Stimpson J. Cat', "admin" => true)
@doc.name.should == 'Stimpson J. Cat'
@doc.admin.should be_false
end

it "should accept nil as constructor's argument without raising exception" do
lambda { @doc_class.new(nil) }.should_not raise_error
end

it "should ignore all attributes if called with no args" do
@doc_class = Doc do
key :name
attr_accessible
end

@doc_class.new(:name => 'Steve Sloan').name.should be_nil
end
end

context "Single collection inherited accessible attributes" do
before do
class ::GrandParent
include MongoMapper::Document
attr_accessible :name
key :name, String
key :site_id, ObjectId
end
GrandParent.collection.remove

class ::Child < ::GrandParent
attr_accessible :position
key :position, Integer
end

class ::GrandChild < ::Child; end

class ::OtherChild < ::GrandParent
attr_accessible :favorite_color
key :favorite_color, String
key :blog_id, ObjectId
end
end

after do
Object.send :remove_const, 'GrandParent' if defined?(::GrandParent)
Object.send :remove_const, 'Child' if defined?(::Child)
Object.send :remove_const, 'GrandChild' if defined?(::GrandChild)
Object.send :remove_const, 'OtherChild' if defined?(::OtherChild)
end

it "should share keys down the inheritance trail" do
GrandParent.accessible_attributes.should == [:name].to_set
Child.accessible_attributes.should == [:name, :position].to_set
GrandChild.accessible_attributes.should == [:name, :position].to_set
OtherChild.accessible_attributes.should == [:name, :favorite_color].to_set
end
end

context "An embedded document with accessible attributes" do
before do
@doc_class = Doc('Project')
@edoc_class = EDoc('Person') do
key :name, String
key :admin, Boolean, :default => false

attr_accessible :name
end
@doc_class.many :people, :class => @edoc_class

@doc = @doc_class.create(:title => 'MongoMapper')
@edoc = @edoc_class.new(:name => 'Steve Sloan')
@doc.people << @edoc
end

it "should have accessible attributes class method" do
@edoc_class.accessible_attributes.should == [:name].to_set
end

it "should default accessible attributes to nil" do
EDoc().accessible_attributes.should be_nil
end

it "should have accessible attributes instance method" do
@edoc.accessible_attributes.should equal(@edoc_class.accessible_attributes)
end

it "should assign inaccessible attribute through accessor" do
@edoc.admin = true
@edoc.admin.should be_true
end

it "should ignore inaccessible attribute on #update_attributes" do
@edoc.update_attributes(:name => 'Ren Hoek', :admin => true)
@edoc.name.should == 'Ren Hoek'
@edoc.admin.should be_false
end

it "should ignore inaccessible attribute on #update_attributes!" do
@edoc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
@edoc.name.should == 'Stimpson J. Cat'
@edoc.admin.should be_false
end
end
end
Oops, something went wrong.

0 comments on commit 4699250

Please sign in to comment.