jcnetdev-shoulda 4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +12 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.rdoc +123 -0
  4. data/Rakefile +32 -0
  5. data/bin/convert_to_should_syntax +40 -0
  6. data/init.rb +1 -0
  7. data/lib/shoulda.rb +43 -0
  8. data/lib/shoulda/active_record_helpers.rb +670 -0
  9. data/lib/shoulda/color.rb +77 -0
  10. data/lib/shoulda/controller_tests/controller_tests.rb +467 -0
  11. data/lib/shoulda/controller_tests/formats/html.rb +201 -0
  12. data/lib/shoulda/controller_tests/formats/xml.rb +170 -0
  13. data/lib/shoulda/gem/proc_extensions.rb +14 -0
  14. data/lib/shoulda/gem/shoulda.rb +246 -0
  15. data/lib/shoulda/general.rb +118 -0
  16. data/lib/shoulda/private_helpers.rb +22 -0
  17. data/rails/init.rb +1 -0
  18. data/shoulda.gemspec +109 -0
  19. data/tasks/list_tests.rake +23 -0
  20. data/tasks/yaml_to_shoulda.rake +28 -0
  21. data/test/README +36 -0
  22. data/test/fixtures/addresses.yml +3 -0
  23. data/test/fixtures/posts.yml +5 -0
  24. data/test/fixtures/taggings.yml +0 -0
  25. data/test/fixtures/tags.yml +9 -0
  26. data/test/fixtures/users.yml +6 -0
  27. data/test/functional/posts_controller_test.rb +43 -0
  28. data/test/functional/users_controller_test.rb +36 -0
  29. data/test/other/context_test.rb +115 -0
  30. data/test/other/helpers_test.rb +80 -0
  31. data/test/other/private_helpers_test.rb +26 -0
  32. data/test/rails_root/app/controllers/application.rb +25 -0
  33. data/test/rails_root/app/controllers/posts_controller.rb +78 -0
  34. data/test/rails_root/app/controllers/users_controller.rb +81 -0
  35. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  36. data/test/rails_root/app/helpers/posts_helper.rb +2 -0
  37. data/test/rails_root/app/helpers/users_helper.rb +2 -0
  38. data/test/rails_root/app/models/address.rb +4 -0
  39. data/test/rails_root/app/models/dog.rb +4 -0
  40. data/test/rails_root/app/models/flea.rb +3 -0
  41. data/test/rails_root/app/models/post.rb +11 -0
  42. data/test/rails_root/app/models/tag.rb +8 -0
  43. data/test/rails_root/app/models/tagging.rb +4 -0
  44. data/test/rails_root/app/models/user.rb +17 -0
  45. data/test/rails_root/app/views/layouts/posts.rhtml +17 -0
  46. data/test/rails_root/app/views/layouts/users.rhtml +17 -0
  47. data/test/rails_root/app/views/posts/edit.rhtml +27 -0
  48. data/test/rails_root/app/views/posts/index.rhtml +25 -0
  49. data/test/rails_root/app/views/posts/new.rhtml +26 -0
  50. data/test/rails_root/app/views/posts/show.rhtml +18 -0
  51. data/test/rails_root/app/views/users/edit.rhtml +22 -0
  52. data/test/rails_root/app/views/users/index.rhtml +22 -0
  53. data/test/rails_root/app/views/users/new.rhtml +21 -0
  54. data/test/rails_root/app/views/users/show.rhtml +13 -0
  55. data/test/rails_root/config/boot.rb +109 -0
  56. data/test/rails_root/config/database.yml +4 -0
  57. data/test/rails_root/config/environment.rb +18 -0
  58. data/test/rails_root/config/environments/sqlite3.rb +0 -0
  59. data/test/rails_root/config/initializers/new_rails_defaults.rb +15 -0
  60. data/test/rails_root/config/routes.rb +6 -0
  61. data/test/rails_root/db/migrate/001_create_users.rb +17 -0
  62. data/test/rails_root/db/migrate/002_create_posts.rb +13 -0
  63. data/test/rails_root/db/migrate/003_create_taggings.rb +12 -0
  64. data/test/rails_root/db/migrate/004_create_tags.rb +11 -0
  65. data/test/rails_root/db/migrate/005_create_dogs.rb +11 -0
  66. data/test/rails_root/db/migrate/006_create_addresses.rb +13 -0
  67. data/test/rails_root/db/migrate/007_create_fleas.rb +11 -0
  68. data/test/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
  69. data/test/rails_root/db/migrate/009_add_ssn_to_users.rb +9 -0
  70. data/test/rails_root/db/schema.rb +0 -0
  71. data/test/rails_root/log/.keep +0 -0
  72. data/test/rails_root/public/.htaccess +40 -0
  73. data/test/rails_root/public/404.html +30 -0
  74. data/test/rails_root/public/422.html +30 -0
  75. data/test/rails_root/public/500.html +30 -0
  76. data/test/rails_root/script/console +3 -0
  77. data/test/rails_root/script/generate +3 -0
  78. data/test/rails_root/vendor/plugins/.keep +0 -0
  79. data/test/test_helper.rb +35 -0
  80. data/test/unit/address_test.rb +7 -0
  81. data/test/unit/dog_test.rb +7 -0
  82. data/test/unit/flea_test.rb +7 -0
  83. data/test/unit/post_test.rb +14 -0
  84. data/test/unit/tag_test.rb +12 -0
  85. data/test/unit/tagging_test.rb +8 -0
  86. data/test/unit/user_test.rb +32 -0
  87. metadata +148 -0
@@ -0,0 +1,8 @@
1
+ class Tag < ActiveRecord::Base
2
+ has_many :taggings, :dependent => :destroy
3
+ has_many :posts, :through => :taggings
4
+
5
+ validates_length_of :name, :minimum => 2
6
+
7
+ attr_accessible :name
8
+ end
@@ -0,0 +1,4 @@
1
+ class Tagging < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :tag
4
+ end
@@ -0,0 +1,17 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :posts
3
+ has_many :dogs, :foreign_key => :owner_id
4
+
5
+ has_one :address, :as => :addressable
6
+
7
+ attr_protected :password
8
+ attr_readonly :name
9
+
10
+ validates_format_of :email, :with => /\w*@\w*.com/
11
+ validates_length_of :email, :in => 1..100
12
+ validates_inclusion_of :age, :in => 1..100
13
+ validates_acceptance_of :eula
14
+ validates_uniqueness_of :email, :scope => :name
15
+ validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
16
+ validates_numericality_of :ssn
17
+ 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,13 @@
1
+ <p>
2
+ <b>Email:</b>
3
+ <%=h @user.email %>
4
+ </p>
5
+
6
+ <p>
7
+ <b>Age:</b>
8
+ <%=h @user.age %>
9
+ </p>
10
+
11
+
12
+ <%= link_to 'Edit', edit_user_path(@user) %> |
13
+ <%= 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!
@@ -0,0 +1,4 @@
1
+ sqlite3:
2
+ :adapter: sqlite3
3
+ # :dbfile: db/sqlite3.db
4
+ :dbfile: ":memory:"
@@ -0,0 +1,18 @@
1
+ # Specifies gem version of Rails to use when vendor/rails is not present
2
+ old_verbose, $VERBOSE = $VERBOSE, nil
3
+ RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
4
+ $VERBOSE = old_verbose
5
+
6
+ require File.join(File.dirname(__FILE__), 'boot')
7
+
8
+ Rails::Initializer.run do |config|
9
+ # Someday, I'm going to find a way of getting rid of that symlink...
10
+ # config.plugin_paths = ['../../../']
11
+ # config.plugins = [:shoulda]
12
+ config.log_level = :debug
13
+ config.cache_classes = false
14
+ config.whiny_nils = true
15
+ # config.load_paths << File.join(File.dirname(__FILE__), *%w{.. .. .. lib})
16
+ end
17
+
18
+ # Dependencies.log_activity = true
File without changes
@@ -0,0 +1,15 @@
1
+ # These settings change the behavior of Rails 2 apps and will be defaults
2
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
3
+
4
+ # Include Active Record class name as root for JSON serialized output.
5
+ ActiveRecord::Base.include_root_in_json = true
6
+
7
+ # Store the full class name (including module namespace) in STI type column.
8
+ ActiveRecord::Base.store_full_sti_class = true
9
+
10
+ # Use ISO 8601 format for JSON serialized times and dates.
11
+ ActiveSupport.use_standard_json_time_format = true
12
+
13
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
14
+ # if you're including raw json in an HTML page.
15
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :posts
4
+ map.resources :users, :has_many => :posts
5
+
6
+ end
@@ -0,0 +1,17 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.column :name, :string
5
+ t.column :email, :string
6
+ t.column :age, :integer
7
+ end
8
+ add_index :users, :email
9
+ add_index :users, :name
10
+ add_index :users, :age
11
+ add_index :users, [:email, :name]
12
+ end
13
+
14
+ def self.down
15
+ drop_table :users
16
+ end
17
+ end