This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Spec | |
| module Matchers | |
| RSpec::Matchers.define :have_errors_on do |field| | |
| chain :with_message do |message| | |
| @message = message | |
| end | |
| match do |model| | |
| model.valid? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_record' | |
| require 'dm-core' | |
| require 'dm-mysql-adapter' | |
| require 'dm-migrations' | |
| require 'dm-validations' | |
| DataMapper.setup :default, "mysql://localhost/tests" | |
| module DM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby-1.9.2-p0 > u = User.first | |
| => #<User ... | |
| ruby-1.9.2-p0 > u.children_valid? | |
| => true | |
| ruby-1.9.2-p0 > u.user_roles << UserRole.new | |
| => [#<UserRole @user_id=1 @role_id=10 @division_id=7>, #<UserRole @user_id=1 @role_id=nil @division_id=nil>] | |
| ruby-1.9.2-p0 > u.children_valid? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Role.validates_presence_of :name | |
| user = User.get(1) | |
| user.attributes = { :roles => [{:name => 'foo'}, {:name => nil}] } | |
| user.save # returns false | |
| user.valid? # returns true | |
| # you cannot validate roles here in before :valid? hook b/c it's not called in the example above! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe PostsController do | |
| describe "GET index" do | |
| subject { get :index } | |
| it { should assign_to(:posts).with(Post.all) } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'dm-core' | |
| require "dm-migrations" | |
| require 'dm-sqlite-adapter' | |
| DataMapper.setup(:default, 'sqlite::memory:') | |
| DataMapper.auto_upgrade! | |
| class Event | |
| include DataMapper::Resource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rails | |
| module DataMapper | |
| class Storage | |
| class Mongo < Storage | |
| def _create | |
| end | |
| def _drop | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| # encoding: utf-8 | |
| require 'dm-sqlite-adapter' | |
| require 'dm-migrations' | |
| require 'dm-validations' | |
| DataMapper.setup :default, "sqlite::memory:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| # encoding: utf-8 | |
| require 'dm-sqlite-adapter' | |
| require 'dm-migrations' | |
| require 'dm-validations' | |
| DataMapper.setup :default, "sqlite::memory:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "dm-core" | |
| require "dm-migrations" | |
| require "dm-validations" | |
| require "dm-validations-ext" | |
| DataMapper.setup :default, "sqlite::memory" | |
| class User | |
| include DataMapper::Resource |