svenaas-woulda 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -48,6 +48,11 @@ class RoleTest < Test::Unit::TestCase
48
48
  should_act_as_enumerated
49
49
  end
50
50
 
51
+ # lazy_http
52
+ class PageControllerTest < ActionController::TestCase
53
+ lazy_get :index, :about_us, :contact
54
+ end
55
+
51
56
  # paperclip
52
57
  class UserTest < Test::Unit::TestCase
53
58
  should_have_attached_file :avatar
@@ -71,7 +76,13 @@ end
71
76
  # acts_as_state_machine
72
77
  class OrderTest < Test::Unit::TestCase
73
78
  should_act_as_state_machine :initial => :open, :states => [:closed], :events => {:close_order => {:to => :closed, :from :open}}
74
- end</code></pre>
79
+ end
80
+
81
+ # acts_as_versioned
82
+ class ProductTest < Test::Unit::TestCase
83
+ should_act_as_versioned
84
+ end
85
+ </code></pre>
75
86
 
76
87
  h2. The source
77
88
 
data/Rakefile CHANGED
@@ -5,11 +5,11 @@ require 'rake/rdoctask'
5
5
  begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |s|
8
- s.name = "woulda"
8
+ s.name = "svenaas-woulda"
9
9
  s.summary = "woulda is a home for shoulda macros that don't belong in the main shoulda library"
10
10
  s.email = ["sean@seanhussey.com", "josh@technicalpickles.com"]
11
11
  s.homepage = "http://github.com/seanhussey/woulda"
12
- s.description = "TODO"
12
+ s.description = "No description yet."
13
13
  s.authors = ["Sean Hussey", "Josh Nichols"]
14
14
  s.add_dependency "thoughtbot-shoulda", ">= 2.10.2"
15
15
  s.rubyforge_project = "woulda"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 1
3
3
  :major: 0
4
- :minor: 2
4
+ :minor: 3
data/lib/woulda.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  woulda_dir = File.expand_path(File.dirname(__FILE__)) + '/woulda'
2
2
 
3
3
  # Standalone Macros
4
+ require "#{woulda_dir}/lazy_http"
4
5
  require "#{woulda_dir}/should_raise"
5
6
 
6
7
  # Macros for gems and plugins
@@ -15,3 +16,5 @@ require "#{woulda_dir}/will_paginate" if defined? WillPaginate
15
16
  require "#{woulda_dir}/acts_as_solr" if defined? ActsAsSolr
16
17
  require "#{woulda_dir}/acts_as_state_machine" if defined? ScottBarron::Acts::StateMachine
17
18
  require "#{woulda_dir}/acts_as_xapian" if defined? ActsAsXapian
19
+ require "#{woulda_dir}/acts_as_versioned" if defined? ActiveRecord::Acts::Versioned
20
+ require "#{woulda_dir}/woulda_workflow" if defined? Workflow
@@ -0,0 +1,6 @@
1
+ require 'shoulda'
2
+ require File.dirname(__FILE__) + '/acts_as_versioned/macros'
3
+
4
+ Test::Unit::TestCase.class_eval do
5
+ extend Woulda::ActsAsVersioned::Macros
6
+ end
@@ -0,0 +1,22 @@
1
+ module Woulda
2
+ module ActsAsVersioned
3
+ module Macros
4
+ def should_act_as_versioned
5
+ klass = model_class
6
+ should_have_db_table "#{klass}_versions".tableize
7
+ should_have_db_column :version
8
+
9
+ context "A #{klass.name}" do
10
+ should "include acts as versioned" do
11
+ assert klass.included_modules.include?(ActiveRecord::Acts::Versioned), "#{klass.name} should act_as_versioned"
12
+ end
13
+
14
+ should "be versioned" do
15
+ assert_respond_to klass, :acts_as_versioned, "#{klass.name} should act_as_versioned"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'shoulda'
2
+ require 'woulda/lazy_http/macros'
3
+
4
+ Test::Unit::TestCase.class_eval do
5
+ extend Woulda::LazyHttp::Macros
6
+ end
@@ -0,0 +1,58 @@
1
+ #--
2
+ # Copyright (c) 2009 Phil Misiowiec (phil@webficient.com)
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module Woulda
25
+ module LazyHttp
26
+ module Macros
27
+ # Automatically generates setup, should_respond_with, and should_render_template
28
+ # for one or more controller actions.
29
+ # This macro is intended for simple actions that respond to GET requests.
30
+ # If the action expects parameters, setup your object as a hash.
31
+ #
32
+ # class PageControllerTest < ActionController::TestCase
33
+ # lazy_get :index, :about_us, :contact, {:search => {:query => 'foo'}}
34
+ # end
35
+ #
36
+ # Also compatible with Factory Girl:
37
+ #
38
+ # class MemberControllerTest < ActionController::TestCase
39
+ # lazy_get :show => {:id => Factory(:member).id}
40
+ # end
41
+ def lazy_get(*actions)
42
+ actions.each do |action|
43
+ params = nil
44
+ context "on GET to #{action}" do
45
+ if action.is_a? Hash
46
+ b = action.keys.first
47
+ params = action[b]
48
+ action = b
49
+ end
50
+ setup { get action, params }
51
+ should_respond_with :success
52
+ should_render_template action
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ require 'shoulda'
2
+ require File.dirname(__FILE__) + '/woulda_workflow/macros'
3
+
4
+ Test::Unit::TestCase.class_eval do
5
+ extend Woulda::WouldaWorkflow::Macros
6
+ end
@@ -0,0 +1,90 @@
1
+ module Woulda
2
+ module WouldaWorkflow
3
+ module Macros
4
+ # Example:
5
+ #
6
+ # class Order < ActiveRecord::Base
7
+ # include Workflow
8
+ # workflow do
9
+ # acts_as_state_machine :initial => :open
10
+ #
11
+ # state :open do
12
+ # event :close_order, :transitions_to => :closed
13
+ # end
14
+ # end
15
+ #
16
+ # class OrderTest < Test::Unit::TestCase
17
+ #
18
+ # # check the inital state
19
+ # should_have_workflow :initial => :open
20
+ #
21
+ # # check states in addition to :initial
22
+ # should_have_workflow :initial => :open, :states => [:closed]
23
+ #
24
+ # # check events and transitions
25
+ # should_have_workflow :events => {:close_order => {:to => :closed, :from :open}}
26
+ #
27
+ # # check workflow database column
28
+ # should_have_workflow :db_column => :legacy_column
29
+ #
30
+ # should_have_workflow :initial => :open, :states => [:closed], :events => {:close_order => {:to => :closed, :from :open}}
31
+ # end
32
+ #
33
+ def should_have_workflow(opts={})
34
+ klass = described_type
35
+
36
+ initial_state, states, events, db_column = get_options!([opts], :initial, :states, :events, :workflow_column)
37
+ #initial_state, states, db_column = get_options!([opts], :initial, :states, :workflow_column)
38
+
39
+ states ||= []
40
+ events ||= {}
41
+ db_column ||= :workflow_state
42
+
43
+ context "A #{klass.name}" do
44
+
45
+ should "specify the intended database column for Workflow" do
46
+ assert_equal db_column, klass.workflow_column
47
+ end
48
+
49
+ should_have_db_column db_column
50
+
51
+ should "include the Workflow module" do
52
+ assert klass.included_modules.include?(Workflow)
53
+ end
54
+
55
+ should "define Workflow class methods" do
56
+ assert klass.extended_by.include?(Workflow::WorkflowClassMethods), "#{klass} doesn't define Workflow class methods"
57
+ end
58
+
59
+ should "define Workflow instance methods" do
60
+ assert klass.include?(Workflow::WorkflowInstanceMethods), "#{klass} doesn't define Workflow instance methods"
61
+ end
62
+
63
+ should "have an intital state of #{initial_state}" do
64
+ assert_equal initial_state, klass.workflow_spec.initial_state.name.to_sym, "#{klass} does not have an initial state of #{initial_state}"
65
+ end
66
+
67
+ states.each do |state|
68
+ should "include state #{state}" do
69
+ assert klass.workflow_spec.states.include?(state), "#{klass} does not include state #{state}"
70
+ end
71
+ end
72
+
73
+ events.each do |event, transition|
74
+ from = transition[:from]
75
+ to = transition[:to]
76
+
77
+ should "define an event #{event} on state #{from}" do
78
+ assert klass.workflow_spec.states[from].events.has_key?(event), "#{klass} does not define event #{event} on state #{from}"
79
+ end
80
+
81
+ should "transition to #{to} from #{from} on event #{event}" do
82
+ assert_equal to, klass.workflow_spec.states[from].events[event].transitions_to, "#{event} does not transition to #{to} from #{from}"
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,15 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ protect_from_forgery # :secret => '42b1f1ff31e7bfc73fae880d56c059af'
10
+
11
+ # See ActionController::Base for details
12
+ # Uncomment this to filter the contents of submitted sensitive data parameters
13
+ # from your application log (in this case, all fields with names like "password").
14
+ # filter_parameter_logging :password
15
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -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
+ min_version = '1.1.1'
86
+ unless rubygems_version >= min_version
87
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. 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,67 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Uncomment below to force Rails into production mode when
4
+ # you don't control web/app server and can't set it the proper way
5
+ # ENV['RAILS_ENV'] ||= 'production'
6
+
7
+ # Specifies gem version of Rails to use when vendor/rails is not present
8
+ RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
9
+
10
+ # Bootstrap the Rails environment, frameworks, and default configuration
11
+ require File.join(File.dirname(__FILE__), 'boot')
12
+
13
+ Rails::Initializer.run do |config|
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+ # See Rails::Configuration for more options.
18
+
19
+ # Skip frameworks you're not going to use. To use Rails without a database
20
+ # you must remove the Active Record framework.
21
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
22
+
23
+ # Specify gems that this application depends on.
24
+ # They can then be installed with "rake gems:install" on new installations.
25
+ # config.gem "bj"
26
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
27
+ # config.gem "aws-s3", :lib => "aws/s3"
28
+
29
+ # Only load the plugins named here, in the order given. By default, all plugins
30
+ # in vendor/plugins are loaded in alphabetical order.
31
+ # :all can be used as a placeholder for all plugins not explicitly named
32
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
33
+
34
+ # Add additional load paths for your own custom dirs
35
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
36
+
37
+ # Force all environments to use the same logger level
38
+ # (by default production uses :info, the others :debug)
39
+ # config.log_level = :debug
40
+
41
+ # Make Time.zone default to the specified zone, and make Active Record store time values
42
+ # in the database in UTC, and return them converted to the specified local zone.
43
+ # Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time.
44
+ config.time_zone = 'UTC'
45
+
46
+ # Your secret key for verifying cookie session data integrity.
47
+ # If you change this key, all old sessions will become invalid!
48
+ # Make sure the secret is at least 30 characters and all random,
49
+ # no regular words or you'll be exposed to dictionary attacks.
50
+ config.action_controller.session = {
51
+ :session_key => '_rails_root_session',
52
+ :secret => 'ccb09d77dc16b088b2b9a1e1cdc35121bcf849d35ec0f6712c7760e3c1ac313e45a1f1803aeadebdf23599a0ddc4ae3cb714231e3e2ffd21c141c3dcc6b1e5a4'
53
+ }
54
+
55
+ # Use the database for sessions instead of the cookie-based default,
56
+ # which shouldn't be used to store highly confidential information
57
+ # (create the session table with "rake db:sessions:create")
58
+ # config.action_controller.session_store = :active_record_store
59
+
60
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
61
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
62
+ # like if you have constraints or database-specific column types
63
+ # config.active_record.schema_format = :sql
64
+
65
+ # Activate observers that should always be running
66
+ # config.active_record.observers = :cacher, :garbage_collector
67
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,22 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Use a different logger for distributed setups
8
+ # config.logger = SyslogLogger.new
9
+
10
+ # Full error reports are disabled and caching is turned on
11
+ config.action_controller.consider_all_requests_local = false
12
+ config.action_controller.perform_caching = true
13
+ config.action_view.cache_template_loading = true
14
+
15
+ # Use a different cache store in production
16
+ # config.cache_store = :mem_cache_store
17
+
18
+ # Enable serving of images, stylesheets, and javascripts from an asset server
19
+ # config.action_controller.asset_host = "http://assets.example.com"
20
+
21
+ # Disable delivery errors, bad email addresses will be ignored
22
+ # config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,22 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Disable request forgery protection in test environment
17
+ config.action_controller.allow_forgery_protection = false
18
+
19
+ # Tell Action Mailer not to deliver emails to the real world.
20
+ # The :test delivery method accumulates sent emails in the
21
+ # ActionMailer::Base.deliveries array.
22
+ config.action_mailer.delivery_method = :test
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,17 @@
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
+ if defined?(ActiveRecord)
5
+ # Include Active Record class name as root for JSON serialized output.
6
+ ActiveRecord::Base.include_root_in_json = true
7
+
8
+ # Store the full class name (including module namespace) in STI type column.
9
+ ActiveRecord::Base.store_full_sti_class = true
10
+ end
11
+
12
+ # Use ISO 8601 format for JSON serialized times and dates.
13
+ ActiveSupport.use_standard_json_time_format = true
14
+
15
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
16
+ # if you're including raw json in an HTML page.
17
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing the them or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
@@ -0,0 +1,10 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
+
5
+ # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
6
+ # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
+ require "dispatcher"
8
+
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
+ Dispatcher.dispatch
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class Test::Unit::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require File.dirname(__FILE__) + '/../lib/woulda'
@@ -0,0 +1,144 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ # TODO
4
+ # - Add tests that verify correct behavior when nothing is raised
5
+ # - Add tests for Ruby 1.9?
6
+
7
+ class ShouldRaiseTest < Test::Unit::TestCase
8
+ # All of the basic Ruby 1.8 exceptions, except for 'fatal'
9
+ EXCEPTIONS = [
10
+ Exception,
11
+ NoMemoryError,
12
+ ScriptError,
13
+ LoadError,
14
+ NotImplementedError,
15
+ SyntaxError,
16
+ SecurityError,
17
+ SignalException,
18
+ Interrupt,
19
+ StandardError,
20
+ ArgumentError,
21
+ IndexError,
22
+ IOError,
23
+ EOFError,
24
+ LocalJumpError,
25
+ NameError,
26
+ NoMethodError,
27
+ RangeError,
28
+ FloatDomainError,
29
+ RegexpError,
30
+ RuntimeError,
31
+ SystemCallError,
32
+ ThreadError,
33
+ TypeError,
34
+ ZeroDivisionError,
35
+ SystemExit,
36
+ SystemStackError]
37
+
38
+ EXCEPTIONS_WITH_PARAMS = {
39
+ Interrupt => 0,
40
+ SystemCallError => 2,
41
+ SignalException => 2
42
+ }
43
+
44
+ PLAIN_EXCEPTIONS = EXCEPTIONS - EXCEPTIONS_WITH_PARAMS.keys
45
+
46
+ context "Defining an instance variable in the context setup block" do
47
+ setup do
48
+ @my_instance_variable = 'my instance_variable'
49
+ end
50
+
51
+ should_raise(ArgumentError, :message => 'dummy') do
52
+ #If we don't have access to the variable here, another exception's gonna be raised
53
+ @my_instance_variable.upcase!
54
+ raise ArgumentError, 'dummy'
55
+ end
56
+ end
57
+
58
+ context "Raising all the types of exceptions" do
59
+ PLAIN_EXCEPTIONS.each do |x|
60
+ context "for exception #{x.inspect}, with a straight exception class argument" do
61
+ should_raise(x) { raise x }
62
+ end
63
+ end
64
+
65
+ EXCEPTIONS_WITH_PARAMS.each_pair do |x, p|
66
+ context "for exception #{x.inspect} with param #{p.inspect}, with a :kind_of exception" do
67
+ should_raise(:kind_of => x) { raise x, p }
68
+ end
69
+ end
70
+
71
+ (PLAIN_EXCEPTIONS - [SystemCallError]).each do |x|
72
+ context "for exception #{x.inspect}, with an :instance_of exception" do
73
+ should_raise(:instance_of => x) { raise x }
74
+ end
75
+ end
76
+ end
77
+
78
+ context "Using an unknown param_type" do
79
+ begin
80
+ should_raise(:unknown_param_type => 'foo') {}
81
+ rescue ArgumentError => ex
82
+ #All of this is happening at class definition time
83
+ @@invalid_should_raise_param_exception = ex
84
+ end
85
+
86
+ should "raise an ArgumentError" do
87
+ assert_kind_of ArgumentError, @@invalid_should_raise_param_exception
88
+ end
89
+
90
+ should "give a message that includes the invalid param name" do
91
+ assert_match /:unknown_param_type/, @@invalid_should_raise_param_exception.message
92
+ end
93
+ end
94
+
95
+ should_raise do
96
+ require "more vespene gas"
97
+ end
98
+ # 1 assertion
99
+
100
+ should_raise(LoadError) do
101
+ require "more vespene gas"
102
+ end
103
+ # 1 more restrictive assertion
104
+
105
+ should_raise(:instance_of => LoadError) do
106
+ require "more vespene gas"
107
+ end
108
+ # 1 assertion, the same as should_raise(LoadError)
109
+
110
+ should_raise(:kind_of => ScriptError) do
111
+ require "more vespene gas"
112
+ end
113
+ # 1 assertion, slightly less strict than with :instance_of (note: LoadError < ScriptError)
114
+
115
+ should_raise(:kind_of => LoadError) do
116
+ require "more vespene gas"
117
+ end
118
+
119
+ should_raise(:message => "no such file to load") do
120
+ require "more vespene gas"
121
+ end
122
+ # 2 assertions
123
+
124
+ should_raise(:message => /vespene/) do
125
+ require "more vespene gas"
126
+ end
127
+ # 2 assertions
128
+
129
+ should_raise(LoadError, :message => "such file to load") do
130
+ require "more vespene gas"
131
+ end
132
+ # 2 assertions
133
+
134
+ should_raise(:kind_of => LoadError, :message => "file to load") do
135
+ require "more vespene gas"
136
+ end
137
+ # 2 assertions
138
+
139
+ should_raise(:instance_of => LoadError, :message => "to load") do
140
+ require "more vespene gas"
141
+ end
142
+ # 2 assertions
143
+ end
144
+
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svenaas-woulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sean Hussey
@@ -10,26 +16,26 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2010-01-16 00:00:00 -05:00
19
+ date: 2010-07-28 00:00:00 -04:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: thoughtbot-shoulda
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 35
31
+ segments:
32
+ - 2
33
+ - 10
34
+ - 2
24
35
  version: 2.10.2
25
- version:
26
- description: |
27
- Testing is love. Especially when done with "Shoulda":http://thoughtbot.com/projects/shoulda. Shoulda makes testing your Rails app pretty easy.
28
-
29
- There are tons of Rails plugins and gems out there. It should be easy to test your Rails app that uses these as well. That kind of support doesn't really belong in Shoulda itself, though.
30
-
31
- That's where Woulda comes in.
32
-
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: No description yet.
33
39
  email:
34
40
  - sean@seanhussey.com
35
41
  - josh@technicalpickles.com
@@ -37,68 +43,109 @@ executables: []
37
43
 
38
44
  extensions: []
39
45
 
40
- extra_rdoc_files: []
41
-
46
+ extra_rdoc_files:
47
+ - LICENSE
48
+ - README.textile
42
49
  files:
43
50
  - LICENSE
44
- - Rakefile
45
51
  - README.textile
52
+ - Rakefile
46
53
  - VERSION.yml
47
- - shoulda_macros/woulda_macros.rb
48
- - lib/woulda/acts_as_ferret/macros.rb
54
+ - lib/woulda.rb
49
55
  - lib/woulda/acts_as_ferret.rb
50
- - lib/woulda/acts_as_list/macros.rb
56
+ - lib/woulda/acts_as_ferret/macros.rb
51
57
  - lib/woulda/acts_as_list.rb
52
- - lib/woulda/acts_as_paranoid/macros.rb
58
+ - lib/woulda/acts_as_list/macros.rb
53
59
  - lib/woulda/acts_as_paranoid.rb
54
- - lib/woulda/acts_as_solr/macros.rb
60
+ - lib/woulda/acts_as_paranoid/macros.rb
55
61
  - lib/woulda/acts_as_solr.rb
62
+ - lib/woulda/acts_as_solr/macros.rb
63
+ - lib/woulda/acts_as_state_machine.rb
56
64
  - lib/woulda/acts_as_state_machine/macros_new.rb
57
65
  - lib/woulda/acts_as_state_machine/macros_old.rb
58
- - lib/woulda/acts_as_state_machine.rb
59
- - lib/woulda/acts_as_taggable_on_steroids/macros.rb
60
66
  - lib/woulda/acts_as_taggable_on_steroids.rb
61
- - lib/woulda/acts_as_xapian/macros.rb
67
+ - lib/woulda/acts_as_taggable_on_steroids/macros.rb
68
+ - lib/woulda/acts_as_versioned.rb
69
+ - lib/woulda/acts_as_versioned/macros.rb
62
70
  - lib/woulda/acts_as_xapian.rb
63
- - lib/woulda/attachment_fu/macros.rb
71
+ - lib/woulda/acts_as_xapian/macros.rb
64
72
  - lib/woulda/attachment_fu.rb
65
- - lib/woulda/enumerations_mixin/macros.rb
73
+ - lib/woulda/attachment_fu/macros.rb
66
74
  - lib/woulda/enumerations_mixin.rb
67
- - lib/woulda/paperclip/macros.rb
75
+ - lib/woulda/enumerations_mixin/macros.rb
76
+ - lib/woulda/lazy_http.rb
77
+ - lib/woulda/lazy_http/macros.rb
68
78
  - lib/woulda/paperclip.rb
69
- - lib/woulda/should_raise/macros.rb
79
+ - lib/woulda/paperclip/macros.rb
70
80
  - lib/woulda/should_raise.rb
71
- - lib/woulda/will_paginate/macros.rb
81
+ - lib/woulda/should_raise/macros.rb
72
82
  - lib/woulda/will_paginate.rb
73
- - lib/woulda.rb
83
+ - lib/woulda/will_paginate/macros.rb
84
+ - lib/woulda/woulda_workflow.rb
85
+ - lib/woulda/woulda_workflow/macros.rb
86
+ - shoulda_macros/woulda_macros.rb
87
+ - test/rails_root/app/controllers/application.rb
88
+ - test/rails_root/app/helpers/application_helper.rb
89
+ - test/rails_root/config/boot.rb
90
+ - test/rails_root/config/environment.rb
91
+ - test/rails_root/config/environments/development.rb
92
+ - test/rails_root/config/environments/production.rb
93
+ - test/rails_root/config/environments/test.rb
94
+ - test/rails_root/config/initializers/inflections.rb
95
+ - test/rails_root/config/initializers/mime_types.rb
96
+ - test/rails_root/config/initializers/new_rails_defaults.rb
97
+ - test/rails_root/config/routes.rb
98
+ - test/rails_root/public/dispatch.rb
99
+ - test/rails_root/test/test_helper.rb
100
+ - test/test_helper.rb
101
+ - test/unit/should_raise_test.rb
74
102
  has_rdoc: true
75
103
  homepage: http://github.com/seanhussey/woulda
76
104
  licenses: []
77
105
 
78
106
  post_install_message:
79
107
  rdoc_options:
80
- - --inline-source
81
108
  - --charset=UTF-8
82
109
  require_paths:
83
110
  - lib
84
111
  required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
85
113
  requirements:
86
114
  - - ">="
87
115
  - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
88
119
  version: "0"
89
- version:
90
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
91
122
  requirements:
92
123
  - - ">="
93
124
  - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
94
128
  version: "0"
95
- version:
96
129
  requirements: []
97
130
 
98
131
  rubyforge_project: woulda
99
- rubygems_version: 1.3.5
132
+ rubygems_version: 1.3.7
100
133
  signing_key:
101
- specification_version: 2
134
+ specification_version: 3
102
135
  summary: woulda is a home for shoulda macros that don't belong in the main shoulda library
103
- test_files: []
104
-
136
+ test_files:
137
+ - test/rails_root/app/controllers/application.rb
138
+ - test/rails_root/app/helpers/application_helper.rb
139
+ - test/rails_root/config/boot.rb
140
+ - test/rails_root/config/environment.rb
141
+ - test/rails_root/config/environments/development.rb
142
+ - test/rails_root/config/environments/production.rb
143
+ - test/rails_root/config/environments/test.rb
144
+ - test/rails_root/config/initializers/inflections.rb
145
+ - test/rails_root/config/initializers/mime_types.rb
146
+ - test/rails_root/config/initializers/new_rails_defaults.rb
147
+ - test/rails_root/config/routes.rb
148
+ - test/rails_root/public/dispatch.rb
149
+ - test/rails_root/test/test_helper.rb
150
+ - test/test_helper.rb
151
+ - test/unit/should_raise_test.rb