mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
parent
c2e908e58b
commit
42d4de6e97
12 changed files with 20 additions and 30 deletions
|
@ -48,7 +48,7 @@ So readable!
|
|||
Quick macro tests for your ActiveRecord associations and validations:
|
||||
|
||||
class PostTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
should_belong_to :user
|
||||
should_have_many :tags, :through => :taggings
|
||||
|
@ -60,8 +60,6 @@ Quick macro tests for your ActiveRecord associations and validations:
|
|||
end
|
||||
|
||||
class UserTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
|
||||
should_have_many :posts
|
||||
|
||||
should_not_allow_values_for :email, "blah", "b lah"
|
||||
|
|
|
@ -22,11 +22,10 @@ module ThoughtBot # :nodoc:
|
|||
#
|
||||
module Macros
|
||||
# Loads all fixture files (<tt>test/fixtures/*.yml</tt>)
|
||||
# Deprecated: Use <tt>fixtures :all</tt> instead
|
||||
def load_all_fixtures
|
||||
all_fixtures = Dir.glob(File.join(Test::Unit::TestCase.fixture_path, "*.yml")).collect do |f|
|
||||
File.basename(f, '.yml').to_sym
|
||||
end
|
||||
fixtures *all_fixtures
|
||||
warn "[DEPRECATION] load_all_fixtures is deprecated. Use `fixtures :all` instead."
|
||||
fixtures :all
|
||||
end
|
||||
|
||||
# Ensures that the model cannot be saved if one of the attributes listed is not present.
|
||||
|
|
|
@ -12,7 +12,7 @@ module ThoughtBot # :nodoc:
|
|||
#
|
||||
# Example:
|
||||
# class UsersControllerTest < Test::Unit::TestCase
|
||||
# load_all_fixtures
|
||||
# fixtures :all
|
||||
#
|
||||
# def setup
|
||||
# ...normal setup code...
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'posts_controller'
|
|||
class PostsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class PostsControllerTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
def setup
|
||||
@controller = PostsController.new
|
||||
|
@ -25,14 +25,14 @@ class PostsControllerTest < Test::Unit::TestCase
|
|||
resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
|
||||
resource.denied.flash = /what/i
|
||||
resource.denied.redirect = '"/"'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Logged in" do
|
||||
setup do
|
||||
@request.session[:logged_in] = true
|
||||
end
|
||||
|
||||
|
||||
should_be_restful do |resource|
|
||||
resource.parent = :user
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'users_controller'
|
|||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class UsersControllerTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
def setup
|
||||
@controller = UsersController.new
|
||||
|
@ -21,16 +21,16 @@ class UsersControllerTest < Test::Unit::TestCase
|
|||
resource.parent = []
|
||||
resource.actions = [:index, :show, :new, :edit, :update, :create, :destroy]
|
||||
resource.formats = [:html, :xml]
|
||||
|
||||
|
||||
resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13, :ssn => "123456789"}
|
||||
resource.update.params = { :name => "sue" }
|
||||
|
||||
|
||||
resource.create.redirect = "user_url(@user)"
|
||||
resource.update.redirect = "user_url(@user)"
|
||||
resource.destroy.redirect = "users_url"
|
||||
|
||||
|
||||
resource.create.flash = /created/i
|
||||
resource.update.flash = /updated/i
|
||||
resource.destroy.flash = /removed/i
|
||||
resource.destroy.flash = /removed/i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class AddressTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
should_belong_to :addressable
|
||||
should_require_unique_attributes :title, :scoped_to => [:addressable_id, :addressable_type]
|
||||
|
||||
|
||||
should_ensure_length_at_least :zip, 5
|
||||
should_only_allow_numeric_values_for :zip
|
||||
should_only_allow_numeric_values_for :zip
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class DogTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
should_belong_to :user
|
||||
should_belong_to :address
|
||||
should_have_and_belong_to_many :fleas
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class FleaTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
should_have_and_belong_to_many :dogs
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class PostTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
should_belong_to :user
|
||||
should_belong_to :owner
|
||||
should_have_many :tags, :through => :taggings
|
||||
should_have_many :through_tags, :through => :taggings
|
||||
|
||||
|
||||
should_require_unique_attributes :title
|
||||
should_require_attributes :body, :message => /wtf/
|
||||
should_require_attributes :title
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TagTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
|
||||
should_have_many :taggings, :dependent => :destroy
|
||||
should_have_many :posts
|
||||
|
||||
|
||||
should_ensure_length_at_least :name, 2
|
||||
|
||||
should_protect_attributes :secret
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TaggingTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
|
||||
should_belong_to :post
|
||||
should_belong_to :tag
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class UserTest < Test::Unit::TestCase
|
||||
load_all_fixtures
|
||||
fixtures :all
|
||||
|
||||
should_have_many :posts
|
||||
should_have_many :dogs
|
||||
|
|
Loading…
Reference in a new issue