Skip to content

Instantly share code, notes, and snippets.

@phillipkoebbe
Created February 8, 2010 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipkoebbe/298281 to your computer and use it in GitHub Desktop.
Save phillipkoebbe/298281 to your computer and use it in GitHub Desktop.
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
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