Permalink
Browse files

Make stuff work with Rails 3 beta4 and RSpec 2

On both Ruby 1.8.7-p299 and 1.9.2.rc1
  • Loading branch information...
1 parent a8c4765 commit 4c9c9bcefc86ad0ff44611f6d9b413129fe85769 @delitescere delitescere committed with Pairing Workstation Sears Jul 14, 2010
View
5 .gitignore
@@ -3,10 +3,7 @@
/doc/app
/doc/plugins
/log/*
-/tmp/cache/*
-/tmp/pids/*
-/tmp/sessions/*
-/tmp/sockets/*
+/tmp
/vendor/gems
/bin
.DS_Store
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
4 .rvmrc
@@ -1,2 +1,2 @@
-#rvm use 1.8.7@tr3w_time_and_expenses
-rvm use 1.9.2@tr3w_time_and_expenses
+rvm use 1.8.7@tr3w_time_and_expenses
+#rvm use 1.9.2@tr3w_time_and_expenses
View
11 Gemfile
@@ -1,12 +1,15 @@
source :gemcutter
-gem 'rails', :git => 'git://github.com/rails/rails.git'
-# gem "rails", '3.0.0.beta3' # TODO: change to 3.0.0 when released
+#gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem "rails", '3.0.0.beta4' # TODO: change to 3.0.0 when released
# gem "rails", :path => '../rails'
-gem "factory_girl"
gem "haml"
gem "mysql"
gem "rack-contrib"
-gem "rspec-rails"
+group :development, :test do
+ gem "rspec-rails", ">= 2.0.0.beta.17"
+ gem "factory_girl_rails"
+end
+
View
188 Gemfile.lock
@@ -0,0 +1,188 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ abstract (1.0.0)
+ actionmailer (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ mail (~> 2.2.3)
+ actionmailer (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ mail (~> 2.2.3)
+ actionpack (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.5)
+ i18n (~> 0.4.1)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.16)
+ actionpack (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.5)
+ i18n (~> 0.4.1)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.16)
+ activemodel (3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activemodel (3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.16)
+ activerecord (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.16)
+ activeresource (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ activeresource (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ activesupport (3.0.0.beta4)
+ activesupport (3.0.0.beta4)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ builder (2.1.2)
+ diff-lcs (1.1.2)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ factory_girl (1.3.1)
+ factory_girl (1.3.1)
+ factory_girl_rails (1.0)
+ factory_girl (~> 1.3)
+ rails (>= 3.0.0.beta4)
+ factory_girl_rails (1.0)
+ factory_girl (~> 1.3)
+ rails (>= 3.0.0.beta4)
+ haml (3.0.13)
+ haml (3.0.13)
+ i18n (0.4.1)
+ i18n (0.4.1)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ mime-types (1.16)
+ mysql (2.8.1)
+ mysql (2.8.1)
+ nokogiri (1.4.2)
+ nokogiri (1.4.2)
+ polyglot (0.3.1)
+ polyglot (0.3.1)
+ rack (1.1.0)
+ rack (1.1.0)
+ rack-contrib (1.0.1)
+ rack (>= 0.9.1)
+ rack-contrib (1.0.1)
+ rack (>= 0.9.1)
+ rack-mount (0.6.9)
+ rack (>= 1.0.0)
+ rack-mount (0.6.9)
+ rack (>= 1.0.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rails (3.0.0.beta4)
+ actionmailer (= 3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activerecord (= 3.0.0.beta4)
+ activeresource (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ bundler (>= 0.9.26)
+ railties (= 3.0.0.beta4)
+ rails (3.0.0.beta4)
+ actionmailer (= 3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activerecord (= 3.0.0.beta4)
+ activeresource (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ bundler (>= 0.9.26)
+ railties (= 3.0.0.beta4)
+ railties (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+ railties (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+ rake (0.8.7)
+ rake (0.8.7)
+ rspec (2.0.0.beta.17)
+ rspec-core (= 2.0.0.beta.17)
+ rspec-expectations (= 2.0.0.beta.17)
+ rspec-mocks (= 2.0.0.beta.17)
+ rspec (2.0.0.beta.17)
+ rspec-core (= 2.0.0.beta.17)
+ rspec-expectations (= 2.0.0.beta.17)
+ rspec-mocks (= 2.0.0.beta.17)
+ rspec-core (2.0.0.beta.17)
+ rspec-core (2.0.0.beta.17)
+ rspec-expectations (2.0.0.beta.17)
+ diff-lcs (>= 1.1.2)
+ rspec-expectations (2.0.0.beta.17)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.17)
+ rspec-mocks (2.0.0.beta.17)
+ rspec-rails (2.0.0.beta.17)
+ rspec (>= 2.0.0.beta.14)
+ webrat (>= 0.7.0)
+ rspec-rails (2.0.0.beta.17)
+ rspec (>= 2.0.0.beta.14)
+ webrat (>= 0.7.0)
+ thor (0.13.7)
+ thor (0.13.7)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.22)
+ tzinfo (0.3.22)
+ webrat (0.7.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+ webrat (0.7.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ factory_girl_rails
+ haml
+ mysql
+ rack-contrib
+ rails (= 3.0.0.beta4)
+ rspec-rails (>= 2.0.0.beta.17)
View
248 README
@@ -1,243 +1,25 @@
-== Welcome to Rails
+== Welcome to The Rails 3 Way
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
+This is a sample application that will help you follow along in the book.
-This pattern splits the view (also called the presentation) into "dumb" templates
-that are primarily responsible for inserting pre-built data in between HTML tags.
-The model contains the "smart" domain objects (such as Account, Product, Person,
-Post) that holds all the business logic and knows how to persist themselves to
-a database. The controller handles the incoming requests (such as Save New Account,
-Update Product, Show Post) by manipulating the model and directing data to the view.
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
+== Issues
-== Getting Started
+* Assuming OS X 10.6.4
+* Lots of Rails, RSpec, and Bundler things are in flux, as well as Ruby 1.9.
+* This app should work under Ruby 1.8.7-p299 and Ruby 1.9.2.rc1
+* You need mysql 5.1.41 if running Ruby 1.9.2.rc1 (to avoid seg faults)
-1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
- and your application name. Ex: rails myapp
-2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
-3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
-4. Follow the guidelines to start developing your application
+== Setup
-== Web Servers
+For now:
-By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
-with a variety of other web servers.
-
-Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
-suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
-More info at: http://mongrel.rubyforge.org
-
-Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
-Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
-FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
-
-== Apache .htaccess example for FCGI/CGI
-
-# General Apache options
-AddHandler fastcgi-script .fcgi
-AddHandler cgi-script .cgi
-Options +FollowSymLinks +ExecCGI
-
-# If you don't want Rails to look in certain directories,
-# use the following rewrite rules so that Apache won't rewrite certain requests
-#
-# Example:
-# RewriteCond %{REQUEST_URI} ^/notrails.*
-# RewriteRule .* - [L]
-
-# Redirect all requests not available on the filesystem to Rails
-# By default the cgi dispatcher is used which is very slow
-#
-# For better performance replace the dispatcher with the fastcgi one
-#
-# Example:
-# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
-RewriteEngine On
-
-# If your Rails application is accessed via an Alias directive,
-# then you MUST also set the RewriteBase in this htaccess file.
-#
-# Example:
-# Alias /myrailsapp /path/to/myrailsapp/public
-# RewriteBase /myrailsapp
-
-RewriteRule ^$ index.html [QSA]
-RewriteRule ^([^.]+)$ $1.html [QSA]
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
-
-# In case Rails experiences terminal errors
-# Instead of displaying this message you can supply a file here which will be rendered instead
-#
-# Example:
-# ErrorDocument 500 /500.html
-
-ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands running
-on the server.log and development.log. Rails will automatically display debugging
-and runtime information to these files. Debugging info will also be shown in the
-browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code using
-the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
-
-* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two online (and free) books will bring you up to speed on the Ruby language
-and also on programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your Mongrel or
-Webrick server with --debugger. This means that you can break out of execution at any point
-in the code, investigate and change the model, AND then resume execution!
-You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
-Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.find(:all)
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
- #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better is that you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you enter "cont"
-
-
-== Console
-
-You can interact with the domain model by starting the console through <tt>script/console</tt>.
-Here you'll have all parts of the application configured, just like it is when the
-application is running. You can inspect domain models, change values, and save to the
-database. Starting the script without arguments will launch it in the development environment.
-Passing an argument will specify a different environment, like <tt>script/console production</tt>.
-
-To reload your controllers and models after launching the console run <tt>reload!</tt>
-
-== dbconsole
-
-You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
-You would be connected to the database with the credentials defined in database.yml.
-Starting the script without arguments will connect you to the development database. Passing an
-argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
-Currently works for mysql, postgresql and sqlite.
-
-== Description of Contents
-
-app
- Holds all the code that's specific to this particular application.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from ApplicationController
- which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb.
- Most models will descend from ActiveRecord::Base.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
- syntax.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the common
- header/footer method of wrapping views. In your views, define a layout using the
- <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
- call <% yield %> to render the view using this layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
- for you automatically when using script/generate for controllers. Helpers can be used to
- wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all
- the sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when generated
- using <tt>rake doc:app</tt>
-
-lib
- Application specific libraries. Basically, any kind of custom code that doesn't
- belong under controllers, models, or helpers. This directory is in the load path.
-
-public
- The directory available for the web server. Contains subdirectories for images, stylesheets,
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
- set as the DOCUMENT_ROOT of your web server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
- test files will be generated for you and placed in this directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins subdirectory.
- If the app has frozen rails, those gems also go here, under vendor/rails/.
- This directory is in the load path.
+* gem install bundler --pre
+* gem install rails --pre
+* gem install rspec-rails --pre
+* gem install ruby-debug#19 #remove the comment before '19' if on Ruby 1.9
+* bundle install
+* `rake test && rake spec` to run the tests
View
5 Rakefile
@@ -2,9 +2,4 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
-
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
TimeAndExpenses::Application.load_tasks
View
8 app/controllers/billable_weeks_controller.rb
@@ -1,7 +1,13 @@
class BillableWeeksController < ApplicationController
def add_to_timesheet
@billable_week = BillableWeek.new(params[:billable_week])
- y, m, d = params[:date].values_at(:year, :month, :day).map {|n| n.to_i }
+
+ if params[:date].blank?
+ flash[:error] = "Date required"
+ redirect_to :back
+ end
+
+ y, m, d = params[:date].values_at(:year, :month, :day).map(&:to_i)
@billable_week.start_date = Date.new(y,m,d)
@timesheet = Timesheet.find(params[:timesheet_id])
View
2 autotest/discover.rb
@@ -0,0 +1,2 @@
+Autotest.add_discovery { "rails" }
+Autotest.add_discovery { "rspec2" }
View
3 config/application.rb
@@ -16,4 +16,5 @@ class Application < Rails::Application
# Include your application configuration below
# ExceptionNotifier.exception_recipients = %w( jhubert@gmail.com )
-require 'factory_girl'
+require 'factory_girl_rails'
+require 'rspec-rails'
View
1 config/environment.rb
@@ -1,5 +1,6 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
+require File.expand_path('../application', __FILE__)
# Initialize the rails application
TimeAndExpenses::Application.initialize!
View
136 lib/tasks/rspec.rake
@@ -1,136 +0,0 @@
-# rspec_gem_dir = nil
-# Dir["#{Rails.root}/vendor/gems/*"].each do |subdir|
- # rspec_gem_dir = subdir if subdir.gsub("#{Rails.root}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
-# end
-# rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
-
-# if rspec_gem_dir && (test ?d, rspec_plugin_dir)
- # raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
-# end
-
-# if rspec_gem_dir
- # $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
-# elsif File.exist?(rspec_plugin_dir)
- # $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
-# end
-
-begin
- require 'rspec/core'
- require 'rspec/core/rake_task'
-rescue MissingSourceFile
- module Rspec
- module Core
- class RakeTask
- def initialize(name)
- task name do
- # if rspec-rails is a configured gem, this will output helpful material and exit ...
- require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
-
- # ... otherwise, do this:
- raise <<-MSG
-
-#{"*" * 80}
-* You are trying to run an rspec rake task defined in
-* #{__FILE__},
-* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
-#{"*" * 80}
-MSG
- end
- end
- end
- end
- end
-end
-
-Rake.application.instance_variable_get('@tasks').delete('default')
-
-spec_prereq = File.exist?(File.join(Rails.root, 'config', 'database.yml')) ? "db:test:prepare" : :noop
-task :noop do
-end
-
-task :default => :spec
-task :stats => "spec:statsetup"
-
-desc "Run all specs in spec directory (excluding plugin specs)"
-Rspec::Core::RakeTask.new(:spec => spec_prereq)
-
-# namespace :spec do
- # desc "Run all specs in spec directory with RCov (excluding plugin specs)"
- # Rspec::Core::RakeTask.new(:rcov) do |t|
- # t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""]
- # t.spec_files = FileList['spec/**/*_spec.rb']
- # t.rcov = true
- # t.rcov_opts = lambda do
- # IO.readlines("#{Rails.root}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
- # end
- # end
-
- # desc "Print Rspecdoc for all specs (excluding plugin specs)"
- # Rspec::Core::RakeTask.new(:doc) do |t|
- # t.spec_opts = ["--format", "specdoc", "--dry-run"]
- # t.spec_files = FileList['spec/**/*_spec.rb']
- # end
-
- # desc "Print Rspecdoc for all plugin examples"
- # Rspec::Core::RakeTask.new(:plugin_doc) do |t|
- # t.spec_opts = ["--format", "specdoc", "--dry-run"]
- # t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
- # end
-
- # [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
- # desc "Run the code examples in spec/#{sub}"
- # Rspec::Core::RakeTask.new(sub => spec_prereq) do |t|
- # t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""]
- # t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
- # end
- # end
-
- # desc "Run the code examples in vendor/plugins (except RRspec's own)"
- # Rspec::Core::RakeTask.new(:plugins => spec_prereq) do |t|
- # t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""]
- # t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
- # end
-
- # namespace :plugins do
- # desc "Runs the examples for rspec_on_rails"
- # Rspec::Core::RakeTask.new(:rspec_on_rails) do |t|
- # t.spec_opts = ['--options', "\"#{Rails.root}/spec/spec.opts\""]
- # t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
- # end
- # end
-
- # Setup specs for stats
- # task :statsetup do
- # require 'code_statistics'
- # ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
- # ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
- # ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
- # ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
- # ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
- # ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
- # ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
- # ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
- # ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
- # ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
- # ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
- # ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
- # ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
- # ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
- # end
-
- # namespace :db do
- # namespace :fixtures do
- # desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
- # task :load => :environment do
- # ActiveRecord::Base.establish_connection(Rails.env)
- # base_dir = File.join(Rails.root, 'spec', 'fixtures')
- # fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
-
- # require 'active_record/fixtures'
- # (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
- # Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
- # end
- # end
- # end
- # end
-# end
View
2 spec/models/client_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require 'spec_helper'
describe Client do
before do
View
2 spec/spec.opts
@@ -1,2 +0,0 @@
---colour
---format progress
View
51 spec/spec_helper.rb
@@ -1,56 +1,27 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
-require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
+require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
-
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
-Rspec.configure do |config|
- # Remove this line if you don't want Rspec's should and should_not
- # methods or matchers
- require 'rspec/expectations'
- config.include Rspec::Matchers
-
- # If you're not using ActiveRecord you should remove these
- # lines, delete config/database.yml and disable :active_record
- # in your config/boot.rb
- # config.use_transactional_fixtures = true
- # config.use_instantiated_fixtures = false
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
-
- # == Fixtures
- #
- # You can declare fixtures for each example_group like this:
- # describe "...." do
- # fixtures :table_a, :table_b
- #
- # Alternatively, if you prefer to declare them only once, you can
- # do so right here. Just uncomment the next line and replace the fixture
- # names with your fixtures.
- #
- # config.global_fixtures = :table_a, :table_b
- #
- # If you declare global fixtures, be aware that they will be declared
- # for all of your examples, even those that don't use them.
- #
- # You can also declare which fixtures to use (for example fixtures for test/fixtures):
- #
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
- #
+RSpec.configure do |config|
# == Mock Framework
#
- # RSpec uses it's own mocking framework by default. If you prefer to
- # use mocha, flexmock or RR, uncomment the appropriate line:
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
- #
- # == Notes
- #
- # For more information take a look at Rspec::Core::Configuration
+ config.mock_with :rspec
+
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, comment the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
end
View
5 test/functional/account_controller_test.rb
@@ -74,11 +74,12 @@ def test_should_not_remember_me
post :login, :login => 'quentin', :password => 'test', :remember_me => "0"
assert_nil @response.cookies["auth_token"]
end
-
+
def test_should_delete_token_on_logout
login_as :quentin
get :logout
- assert_equal @response.cookies["auth_token"], []
+ # assert_equal @response.cookies["auth_token"], []
+ assert_equal @response.cookies["auth_token"], nil
end
def test_should_login_with_cookie
View
10 test/functional/billing_codes_controller_test.rb
@@ -13,12 +13,12 @@ def test_should_get_new
get :new, :client_id => 1
assert_response :success
end
-
+
def test_should_create_billing_code
old_count = BillingCode.count
post :create, :billing_code => { }, :client_id => 1
assert_equal old_count+1, BillingCode.count
-
+
assert_redirected_to client_billing_code_path(clients(:one), assigns(:billing_code))
end
@@ -31,17 +31,17 @@ def test_should_get_edit
get :edit, :id => 1, :client_id => 1
assert_response :success
end
-
+
def test_should_update_billing_code
put :update, :id => 1, :billing_code => { }, :client_id => 1
assert_redirected_to client_billing_code_path(clients(:one), assigns(:billing_code))
end
-
+
def test_should_destroy_billing_code
old_count = BillingCode.count
delete :destroy, :id => 1, :client_id => 1
assert_equal old_count-1, BillingCode.count
-
+
assert_redirected_to client_billing_codes_path(clients(:one))
end
end
View
10 test/functional/clients_controller_test.rb
@@ -13,12 +13,11 @@ def test_should_get_new
get :new
assert_response :success
end
-
+
def test_should_create_client
old_count = Client.count
- post :create, :client => { }
+ post :create, :client => { :name => 'Zorg' }
assert_equal old_count+1, Client.count
-
assert_redirected_to client_path(assigns(:client))
end
@@ -31,17 +30,16 @@ def test_should_get_edit
get :edit, :id => 1
assert_response :success
end
-
+
def test_should_update_client
put :update, :id => 1, :client => { }
assert_redirected_to client_path(assigns(:client))
end
-
+
def test_should_destroy_client
old_count = Client.count
delete :destroy, :id => 1
assert_equal old_count-1, Client.count
-
assert_redirected_to clients_path
end
end
View
5 test/integration/user_records_hours_test.rb
@@ -1,7 +1,7 @@
-require "#{File.dirname(__FILE__)}/../test_helper"
+require "test_helper"
class UserRecordsHoursTest < ActionController::IntegrationTest
-
+
fixtures :users, :billable_weeks, :billing_codes, :clients, :timesheets
def setup
@@ -19,6 +19,7 @@ def test_login
post("billable_weeks/add_to_timesheet",
:timesheet_id => timesheet.id,
+ :date => { :year => 2010, :month => 7, :day => 14 },
:billable_week => {
:client_id => 3,
:start_date => "December 4 2006",
View
6 test/test2spec_help.rb
@@ -12,10 +12,10 @@
class ActiveSupport::TestCase
def self.fixture_path=(p)
end
-
+
def self.use_transactional_fixtures=(f)
end
-
+
def self.fixture_table_names=(*args)
end
@@ -30,7 +30,7 @@ def self.use_instantiated_fixtures=(*args)
def self.pre_loaded_fixtures=(*args)
end
-
+
def self.fixtures(*table_names)
end
end
View
7 test/test_helper.rb
@@ -1,7 +1,7 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+ENV["RAILS_ENV"] ||= "test"
+require File.expand_path("../../config/environment", __FILE__)
require 'rails/test_help'
-#require 'redgreen'
+# require 'redgreen'
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
@@ -33,5 +33,4 @@ def logged_in(login, password)
assert(user)
yield user
end
-
end
View
10 test/unit/billing_code_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class BillingCodeTest < ActiveSupport::TestCase
fixtures :billing_codes
@@ -8,19 +8,19 @@ def test_self_referential_bidirectional_habtm_association
assert BillingCode.find(1).related.include?(BillingCode.find(2))
assert BillingCode.find(2).related.include?(BillingCode.find(1))
end
-
+
def test_that_deletion_is_bidirectional_too
billing_codes(:travel).related << billing_codes(:development)
billing_codes(:travel).related.delete(billing_codes(:development))
assert !BillingCode.find(1).related.include?(BillingCode.find(2))
-
+
# Perhaps needs a dependent option?
# assert !BillingCode.find(2).related.include?(BillingCode.find(1))
end
-
+
def test_associate_extension_works
billing_codes(:travel).related.associate(billing_codes(:development))
assert BillingCode.find(1).related.include?(BillingCode.find(2))
end
-
+
end
View
6 test/unit/late_notice_test.rb
@@ -1,10 +1,10 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class LateNoticeTest < ActiveSupport::TestCase
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
CHARSET = "utf-8"
- include ActionMailer::Quoting
+ # include ActionMailer::Quoting
def setup
ActionMailer::Base.delivery_method = :test
@@ -15,7 +15,7 @@ def setup
@expected.content_type "text/plain;charset=#{CHARSET}"
@expected.mime_version = '1.0'
end
-
+
def test_nothing
end
View
2 test/unit/team_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class TeamTest < ActiveSupport::TestCase
fixtures :teams
View
18 test/unit/timesheet_test.rb
@@ -1,16 +1,16 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class TimesheetTest < ActiveSupport::TestCase
-
+
fixtures :timesheets, :users
-
+
def test_only_authorized_user_may_be_associated_as_approver
sheet = Timesheet.create
sheet.approver = users(:approver)
assert sheet.save
assert_not_nil sheet.approver(true), "approver assignment failed"
end
-
+
def test_non_authorized_user_cannot_be_associated_as_approver
sheet = Timesheet.create
begin
@@ -20,19 +20,19 @@ def test_non_authorized_user_cannot_be_associated_as_approver
# expected
end
end
-
+
def test_optimistic_locking_behavior
first_instance = Timesheet.find(1)
second_instance = Timesheet.find(1)
-
+
first_instance.approver = users(:approver)
second_instance.approver = users(:approver2)
-
+
assert first_instance.save, "First instance save succeeded"
-
+
assert_raises ActiveRecord::StaleObjectError do
second_instance.save
end
end
-
+
end
View
6 test/unit/user_notifier_test.rb
@@ -1,12 +1,10 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
require 'user_notifier'
class UserNotifierTest < ActiveSupport::TestCase
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
CHARSET = "utf-8"
- include ActionMailer::Quoting
-
def setup
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
@@ -15,7 +13,7 @@ def setup
@expected = Mail.new
@expected.content_type "text/plain;charset=#{CHARSET}"
end
-
+
def test_true
assert true
end
View
2 test/unit/user_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.

0 comments on commit 4c9c9bc

Please sign in to comment.