Created
February 8, 2010 15:57
-
-
Save phillipkoebbe/298281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require File.dirname(__FILE__) + '/../../../../spec/spec_helper' | |
rescue LoadError | |
puts "You need to install rspec in your base app" | |
exit | |
end | |
ActionController::Routing::Routes.draw do |map| | |
map.resources :things | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require File.dirname(__FILE__) + '/../lib/acts_as_single_submit' | |
class ApplicationController < ActionController::Base | |
end | |
class ThingsController < ApplicationController | |
include ActsAsSingleSubmit | |
acts_as_single_submit | |
before_filter :set_session_var, :only => [:create] | |
def create | |
render :text => 'Create complete.' | |
end | |
private | |
def set_session_var | |
session[:bogus_var] = params[:bogus_var] | |
end | |
end | |
describe ThingsController, :type => :controller do | |
it 'should be an instance of ApplicationController' do | |
ThingsController.superclass.should == ApplicationController | |
end | |
it 'should act as single submit' do | |
ThingsController.should respond_to(:acts_as_single_submit) | |
end | |
it 'should have a create action' do | |
ThingsController.new.should respond_to(:create) | |
end | |
it 'one post create should work' do | |
controller.should_receive(:set_session_var).once | |
post :create, {:bogus_var => 'this is bogus'} | |
end | |
it 'double post of same parameter data should not happen' do | |
controller.should_receive(:set_session_var).once | |
post :create, {:bogus_var => 'this is bogus'} | |
end | |
it 'second submit of different data should be allowed' do | |
controller.should_receive(:set_session_var).twice | |
post :create, {:bogus_var => 'this is bogus'} | |
post :create, {:bogus_var => 'this is bogus also'} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment