shoulda 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +12 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +132 -0
- data/Rakefile +72 -0
- data/bin/convert_to_should_syntax +42 -0
- data/lib/shoulda.rb +16 -0
- data/lib/shoulda/action_mailer.rb +10 -0
- data/lib/shoulda/action_mailer/assertions.rb +39 -0
- data/lib/shoulda/active_record.rb +12 -0
- data/lib/shoulda/active_record/assertions.rb +85 -0
- data/lib/shoulda/active_record/macros.rb +703 -0
- data/lib/shoulda/assertions.rb +45 -0
- data/lib/shoulda/context.rb +309 -0
- data/lib/shoulda/controller.rb +30 -0
- data/lib/shoulda/controller/formats/html.rb +201 -0
- data/lib/shoulda/controller/formats/xml.rb +170 -0
- data/lib/shoulda/controller/helpers.rb +64 -0
- data/lib/shoulda/controller/macros.rb +287 -0
- data/lib/shoulda/controller/resource_options.rb +236 -0
- data/lib/shoulda/controller/routing.rb +0 -0
- data/lib/shoulda/controller/routing/macros.rb +0 -0
- data/lib/shoulda/helpers.rb +10 -0
- data/lib/shoulda/macros.rb +80 -0
- data/lib/shoulda/private_helpers.rb +22 -0
- data/lib/shoulda/proc_extensions.rb +14 -0
- data/lib/shoulda/rails.rb +19 -0
- data/lib/shoulda/tasks.rb +3 -0
- data/lib/shoulda/tasks/list_tests.rake +24 -0
- data/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
- data/test/README +36 -0
- data/test/fixtures/addresses.yml +3 -0
- data/test/fixtures/friendships.yml +0 -0
- data/test/fixtures/posts.yml +5 -0
- data/test/fixtures/products.yml +0 -0
- data/test/fixtures/taggings.yml +0 -0
- data/test/fixtures/tags.yml +9 -0
- data/test/fixtures/users.yml +6 -0
- data/test/functional/posts_controller_test.rb +104 -0
- data/test/functional/users_controller_test.rb +36 -0
- data/test/other/context_test.rb +145 -0
- data/test/other/convert_to_should_syntax_test.rb +63 -0
- data/test/other/helpers_test.rb +183 -0
- data/test/other/private_helpers_test.rb +34 -0
- data/test/other/should_test.rb +266 -0
- data/test/rails_root/app/controllers/application.rb +25 -0
- data/test/rails_root/app/controllers/posts_controller.rb +85 -0
- data/test/rails_root/app/controllers/users_controller.rb +81 -0
- data/test/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails_root/app/helpers/posts_helper.rb +2 -0
- data/test/rails_root/app/helpers/users_helper.rb +2 -0
- data/test/rails_root/app/models/address.rb +7 -0
- data/test/rails_root/app/models/dog.rb +5 -0
- data/test/rails_root/app/models/flea.rb +3 -0
- data/test/rails_root/app/models/friendship.rb +4 -0
- data/test/rails_root/app/models/post.rb +12 -0
- data/test/rails_root/app/models/product.rb +12 -0
- data/test/rails_root/app/models/tag.rb +8 -0
- data/test/rails_root/app/models/tagging.rb +4 -0
- data/test/rails_root/app/models/user.rb +28 -0
- data/test/rails_root/app/views/layouts/posts.rhtml +17 -0
- data/test/rails_root/app/views/layouts/users.rhtml +17 -0
- data/test/rails_root/app/views/posts/edit.rhtml +27 -0
- data/test/rails_root/app/views/posts/index.rhtml +25 -0
- data/test/rails_root/app/views/posts/new.rhtml +26 -0
- data/test/rails_root/app/views/posts/show.rhtml +18 -0
- data/test/rails_root/app/views/users/edit.rhtml +22 -0
- data/test/rails_root/app/views/users/index.rhtml +22 -0
- data/test/rails_root/app/views/users/new.rhtml +21 -0
- data/test/rails_root/app/views/users/show.rhtml +13 -0
- data/test/rails_root/config/boot.rb +109 -0
- data/test/rails_root/config/database.yml +4 -0
- data/test/rails_root/config/environment.rb +14 -0
- data/test/rails_root/config/environments/sqlite3.rb +0 -0
- data/test/rails_root/config/initializers/new_rails_defaults.rb +15 -0
- data/test/rails_root/config/initializers/shoulda.rb +8 -0
- data/test/rails_root/config/routes.rb +6 -0
- data/test/rails_root/db/migrate/001_create_users.rb +18 -0
- data/test/rails_root/db/migrate/002_create_posts.rb +13 -0
- data/test/rails_root/db/migrate/003_create_taggings.rb +12 -0
- data/test/rails_root/db/migrate/004_create_tags.rb +11 -0
- data/test/rails_root/db/migrate/005_create_dogs.rb +12 -0
- data/test/rails_root/db/migrate/006_create_addresses.rb +14 -0
- data/test/rails_root/db/migrate/007_create_fleas.rb +11 -0
- data/test/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
- data/test/rails_root/db/migrate/009_create_products.rb +17 -0
- data/test/rails_root/db/migrate/010_create_friendships.rb +14 -0
- data/test/rails_root/db/schema.rb +0 -0
- data/test/rails_root/log/sqlite3.log +0 -0
- data/test/rails_root/public/404.html +30 -0
- data/test/rails_root/public/422.html +30 -0
- data/test/rails_root/public/500.html +30 -0
- data/test/rails_root/script/console +3 -0
- data/test/rails_root/script/generate +3 -0
- data/test/test_helper.rb +33 -0
- data/test/unit/address_test.rb +10 -0
- data/test/unit/dog_test.rb +7 -0
- data/test/unit/flea_test.rb +6 -0
- data/test/unit/friendship_test.rb +6 -0
- data/test/unit/post_test.rb +15 -0
- data/test/unit/product_test.rb +27 -0
- data/test/unit/tag_test.rb +14 -0
- data/test/unit/tagging_test.rb +6 -0
- data/test/unit/user_test.rb +52 -0
- metadata +170 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
belongs_to :owner, :foreign_key => :user_id, :class_name => 'User'
|
4
|
+
has_many :taggings
|
5
|
+
has_many :tags, :through => :taggings
|
6
|
+
has_many :through_tags, :through => :taggings, :source => :tag
|
7
|
+
|
8
|
+
validates_uniqueness_of :title
|
9
|
+
validates_presence_of :title
|
10
|
+
validates_presence_of :body, :message => 'Seriously... wtf'
|
11
|
+
validates_numericality_of :user_id
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Product < ActiveRecord::Base
|
2
|
+
validates_presence_of :title
|
3
|
+
|
4
|
+
validates_inclusion_of :price, :in => 0..99, :unless => :tangible
|
5
|
+
validates_format_of :size, :with => /^\d+\D+$/, :unless => :tangible
|
6
|
+
|
7
|
+
validates_presence_of :price, :if => :tangible
|
8
|
+
validates_inclusion_of :price, :in => 1..9999, :if => :tangible
|
9
|
+
validates_inclusion_of :weight, :in => 1..100, :if => :tangible
|
10
|
+
validates_format_of :size, :with => /.+x.+x.+/, :if => :tangible
|
11
|
+
validates_length_of :size, :in => 5..20, :if => :tangible
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
has_many :posts
|
3
|
+
has_many :dogs, :foreign_key => :owner_id
|
4
|
+
|
5
|
+
has_many :friendships
|
6
|
+
has_many :friends, :through => :friendships
|
7
|
+
|
8
|
+
has_one :address, :as => :addressable, :dependent => :destroy
|
9
|
+
|
10
|
+
named_scope :old, :conditions => "age > 50"
|
11
|
+
named_scope :eighteen, :conditions => { :age => 18 }
|
12
|
+
named_scope :recent, lambda {|count| { :limit => count } }
|
13
|
+
|
14
|
+
def self.recent_via_method(count)
|
15
|
+
scoped(:limit => count)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_protected :password
|
19
|
+
attr_readonly :name
|
20
|
+
|
21
|
+
validates_format_of :email, :with => /\w*@\w*.com/
|
22
|
+
validates_length_of :email, :in => 1..100
|
23
|
+
validates_inclusion_of :age, :in => 1..100
|
24
|
+
validates_acceptance_of :eula
|
25
|
+
validates_uniqueness_of :email, :scope => :name
|
26
|
+
validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
|
27
|
+
validates_numericality_of :ssn
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title>Posts: <%= controller.action_name %></title>
|
8
|
+
<%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title>Users: <%= controller.action_name %></title>
|
8
|
+
<%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h1>Editing post</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :post %>
|
4
|
+
|
5
|
+
<% form_for(:post, :url => user_post_path(@post.user, @post), :html => { :method => :put }) do |f| %>
|
6
|
+
<p>
|
7
|
+
<b>User</b><br />
|
8
|
+
<%= f.text_field :user_id %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Title</b><br />
|
13
|
+
<%= f.text_field :title %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<b>Body</b><br />
|
18
|
+
<%= f.text_area :body %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<%= submit_tag "Update" %>
|
23
|
+
</p>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<%= link_to 'Show', user_post_path(@post.user, @post) %> |
|
27
|
+
<%= link_to 'Back', user_posts_path(@post.user) %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing posts</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>User</th>
|
6
|
+
<th>Title</th>
|
7
|
+
<th>Body</th>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<% for post in @posts %>
|
11
|
+
<tr>
|
12
|
+
<td><%=h post.user_id %></td>
|
13
|
+
<td><%=h post.title %></td>
|
14
|
+
<td><%=h post.body %></td>
|
15
|
+
<td><%= link_to 'Show', user_post_path(post.user, post) %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_user_post_path(post.user, post) %></td>
|
17
|
+
<td><%= link_to 'Destroy', user_post_path(post.user, post), :confirm => 'Are you sure?',
|
18
|
+
:method => :delete %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br />
|
24
|
+
|
25
|
+
<%= link_to 'New post', new_user_post_path(post.user) %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<h1>New post</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :post %>
|
4
|
+
|
5
|
+
<% form_for(:post, :url => user_posts_path(@user)) do |f| %>
|
6
|
+
<p>
|
7
|
+
<b>User</b><br />
|
8
|
+
<%= f.text_field :user_id %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Title</b><br />
|
13
|
+
<%= f.text_field :title %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<b>Body</b><br />
|
18
|
+
<%= f.text_area :body %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<%= submit_tag "Create" %>
|
23
|
+
</p>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<%= link_to 'Back', user_posts_path(@user) %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<p>
|
2
|
+
<b>User:</b>
|
3
|
+
<%=h @post.user_id %>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<b>Title:</b>
|
8
|
+
<%=h @post.title %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Body:</b>
|
13
|
+
<%=h @post.body %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
|
17
|
+
<%= link_to 'Edit', edit_user_post_path(@post.user, @post) %> |
|
18
|
+
<%= link_to 'Back', user_posts_path(@post.user) %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>Editing user</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :user %>
|
4
|
+
|
5
|
+
<% form_for(:user, :url => user_path(@user), :html => { :method => :put }) do |f| %>
|
6
|
+
<p>
|
7
|
+
<b>Email</b><br />
|
8
|
+
<%= f.text_field :email %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Age</b><br />
|
13
|
+
<%= f.text_field :age %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<%= submit_tag "Update" %>
|
18
|
+
</p>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<%= link_to 'Show', user_path(@user) %> |
|
22
|
+
<%= link_to 'Back', users_path %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>Listing users</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Email</th>
|
6
|
+
<th>Age</th>
|
7
|
+
</tr>
|
8
|
+
|
9
|
+
<% for user in @users %>
|
10
|
+
<tr>
|
11
|
+
<td><%=h user.email %></td>
|
12
|
+
<td><%=h user.age %></td>
|
13
|
+
<td><%= link_to 'Show', user_path(user) %></td>
|
14
|
+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
15
|
+
<td><%= link_to 'Destroy', user_path(user), :confirm => 'Are you sure?', :method => :delete %></td>
|
16
|
+
</tr>
|
17
|
+
<% end %>
|
18
|
+
</table>
|
19
|
+
|
20
|
+
<br />
|
21
|
+
|
22
|
+
<%= link_to 'New user', new_user_path %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<h1>New user</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :user %>
|
4
|
+
|
5
|
+
<% form_for(:user, :url => users_path) do |f| %>
|
6
|
+
<p>
|
7
|
+
<b>Email</b><br />
|
8
|
+
<%= f.text_field :email %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Age</b><br />
|
13
|
+
<%= f.text_field :age %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<%= submit_tag "Create" %>
|
18
|
+
</p>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<%= link_to 'Back', users_path %>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class GemBoot < Boot
|
51
|
+
def load_initializer
|
52
|
+
self.class.load_rubygems
|
53
|
+
load_rails_gem
|
54
|
+
require 'initializer'
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_rails_gem
|
58
|
+
if version = self.class.gem_version
|
59
|
+
gem 'rails', version
|
60
|
+
else
|
61
|
+
gem 'rails'
|
62
|
+
end
|
63
|
+
rescue Gem::LoadError => load_error
|
64
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def rubygems_version
|
70
|
+
Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
|
71
|
+
end
|
72
|
+
|
73
|
+
def gem_version
|
74
|
+
if defined? RAILS_GEM_VERSION
|
75
|
+
RAILS_GEM_VERSION
|
76
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
77
|
+
ENV['RAILS_GEM_VERSION']
|
78
|
+
else
|
79
|
+
parse_gem_version(read_environment_rb)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_rubygems
|
84
|
+
require 'rubygems'
|
85
|
+
|
86
|
+
unless rubygems_version >= '0.9.4'
|
87
|
+
$stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue LoadError
|
92
|
+
$stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_gem_version(text)
|
97
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def read_environment_rb
|
102
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# All that for this:
|
109
|
+
Rails.boot!
|