Permalink
Browse files

Specs really ready for framework testing (Rails 2 test working)

  • Loading branch information...
1 parent 7622898 commit b019166ae36da9d29ea2368ced344ae8ff8b528d @winton committed Dec 23, 2010
View
@@ -3,6 +3,7 @@
coverage
pkg
spec/config/database.yml
+spec/fixtures/build
spec/log
tmp
vendor
@@ -10,7 +10,9 @@ class Gems
:active_wrapper => '=0.3.4',
:also_migrate => '0.2.1',
:externals => '1.0.2',
+ :framework_fixture => '0.1.2',
:mover => '0.3.3',
+ :'rack-test' => '0.5.6',
:rake => '=0.8.7',
:rspec => '=1.3.1'
}
@@ -20,7 +22,9 @@ class Gems
:gemspec_dev => [ :active_wrapper, :externals, :rspec ],
:lib => [ :also_migrate, :mover ],
:rake => [ :rake, :rspec ],
- :spec => [ :activesupport, :active_wrapper, :rspec ],
+ :spec => [ :'rack-test', :rspec ],
+ :spec_first => [ :framework_fixture ],
+ :spec_non_framework => [ :activesupport, :active_wrapper ],
:spec_rake => [ :active_wrapper ]
}
@@ -1,86 +1,77 @@
require 'spec_helper'
-describe ActsAsArchive do
+unless FrameworkFixture.framework
+ describe ActsAsArchive do
- before(:each) do
- [ 8, 0, 8 ].each { |v| $db.migrate(v) }
-
- @record = Record.create :belongs_to_id => BelongsTo.create.id
-
- HasOne.create :record_id => @record.id
-
- HasMany.create :record_id => @record.id
- HasMany.create :record_id => @record.id
-
- Record.first.has_many_throughs.create
- Record.first.has_many_throughs.create
-
- Record.first.create_has_one_through_through.create_has_one_through
-
- @lengths = {
- :record => 1,
- :belongs_to => 1,
- :has_one => 1,
- :has_many => 2,
- :has_many_through => 2,
- :has_many_through_through => 2,
- :has_one_through => 1,
- :has_one_through_through => 1
- }
-
- @zero_lengths = @lengths.inject({}) do |hash, (key, value)|
- hash[key] = 0
- hash
+ before(:each) do
+ [ 8, 0, 8 ].each { |v| $db.migrate(v) }
+ @record, @lengths, @zero_lengths = setup_records
end
- end
- it "should create records" do
- original, archive = all_records
- verify_lengths original, @lengths
- verify_attributes original
- end
+ it "should create records" do
+ original, archive = all_records
+ verify_lengths original, @lengths
+ verify_attributes original
+ end
- %w(delete delete_all destroy destroy_all).each do |type|
- describe type do
- it "should move records to archive tables" do
- case type
- when 'delete', 'destroy'
- @record.send type
- when 'delete_all', 'destroy_all'
- Record.send type
- end
+ %w(delete delete_all destroy destroy_all).each do |type|
+ describe type do
+ it "should move records to archive tables" do
+ case type
+ when 'delete', 'destroy'
+ @record.send type
+ when 'delete_all', 'destroy_all'
+ Record.send type
+ end
- original, archive = all_records
+ original, archive = all_records
- case type
- when 'delete', 'delete_all'
- archive[:record].length.should == 1
- original[:record].length.should == 0
+ case type
+ when 'delete', 'delete_all'
+ archive[:record].length.should == 1
+ original[:record].length.should == 0
- verify_lengths archive, @zero_lengths, :exclude => [ :record ]
- verify_lengths original, @lengths, :exclude => [ :record ]
+ verify_lengths archive, @zero_lengths, :exclude => [ :record ]
+ verify_lengths original, @lengths, :exclude => [ :record ]
- verify_attributes archive, :only => [ :record ]
+ verify_attributes archive, :only => [ :record ]
- when 'destroy', 'destroy_all'
- verify_lengths archive, @lengths
- verify_lengths original, @zero_lengths
+ when 'destroy', 'destroy_all'
+ verify_lengths archive, @lengths
+ verify_lengths original, @zero_lengths
- verify_attributes archive
+ verify_attributes archive
+ end
end
- end
- it "should move records back to original tables" do
- @record.destroy
- Record::Archive.first.destroy
+ it "should move records back to original tables" do
+ @record.destroy
+ Record::Archive.first.destroy
- original, archive = all_records
+ original, archive = all_records
- verify_lengths original, @lengths
- verify_lengths archive, @zero_lengths
+ verify_lengths original, @lengths
+ verify_lengths archive, @zero_lengths
- verify_attributes original
+ verify_attributes original
+ end
end
end
end
+end
+
+if FrameworkFixture.rails == '<3'
+ describe 'Rails 2' do
+
+ include Rack::Test::Methods
+
+ def app
+ FrameworkFixture.app.call
+ end
+
+ it "should have a pulse" do
+ get "/pulse"
+ last_response.body.should == '1'
+ end
+ end
end
@@ -0,0 +1,33 @@
+rails:
+ <3:
+ frameworks/rails2:
+ - app/controllers/application_controller.rb
+ - config/routes.rb
+ - vendor/plugins/plugin/rails/init.rb
+ helpers: &helpers
+ - app/helpers/verify_helper.rb
+ models: &models
+ - app/models/belongs_to.rb
+ - app/models/has_many.rb
+ - app/models/has_many_through.rb
+ - app/models/has_many_through_through.rb
+ - app/models/has_one.rb
+ - app/models/has_one_through.rb
+ - app/models/has_one_through_through.rb
+ - app/models/record.rb
+ <4:
+ frameworks/rails3:
+ - app/controllers/application_controller.rb
+ - config/routes.rb
+ - Gemfile
+ helpers:
+ <<: *helpers
+ models:
+ <<: *models
+sinatra:
+ <1:
+ frameworks/sinatra:
+ - application.rb
+ <2:
+ frameworks/sinatra:
+ - application.rb
@@ -0,0 +1,14 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+
+ def pulse
+ render :text => '1'
+ end
+end
@@ -0,0 +1 @@
+require "#{$root}/lib/acts_as_archive"
@@ -0,0 +1,46 @@
+ActionController::Routing::Routes.draw do |map|
+ # The priority is based upon order of creation: first created -> highest priority.
+
+ # Sample of regular route:
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # map.resources :products
+
+ # Sample resource route with options:
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+
+ # Sample resource route with sub-resources:
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
+
+ # Sample resource route with more complex sub-resources
+ # map.resources :products do |products|
+ # products.resources :comments
+ # products.resources :sales, :collection => { :recent => :get }
+ # end
+
+ # Sample resource route within a namespace:
+ # map.namespace :admin do |admin|
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
+ # admin.resources :products
+ # end
+
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
+ # map.root :controller => "welcome"
+
+ # See how all your routes lay out with "rake routes"
+
+ # Install the default routes as the lowest priority.
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
+ # consider removing or commenting them out if you're using named routes and resources.
+
+ # map.connect ':controller/:action/:id'
+ # map.connect ':controller/:action/:id.:format'
+
+ map.connect 'pulse', :controller => 'application', :action => 'pulse'
+end
@@ -0,0 +1,34 @@
+source 'http://rubygems.org'
+
+gem 'framework_fixture', '0.1.2'
+gem 'rails', '3.0.3'
+gem 'rspec'
+
+gem 'acts_as_archive', :path => "../../../../../"
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
+# end
@@ -0,0 +1,7 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ def pulse
+ render :text => '1'
+ end
+end
@@ -0,0 +1,60 @@
+Rails3::Application.routes.draw do
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => "welcome#index"
+
+ # See how all your routes lay out with "rake routes"
+
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
+
+ match 'pulse' => 'application#pulse'
+end
@@ -0,0 +1,14 @@
+require 'sinatra/base'
+require 'smart_asset'
+
+class Application < Sinatra::Base
+
+ set :app_file, __FILE__
+ set :views, File.dirname(__FILE__)
+
+ include SmartAsset::Adapters::Sinatra
+
+ get '/pulse' do
+ '1'
+ end
+end
Oops, something went wrong.

0 comments on commit b019166

Please sign in to comment.