Sha256: c1c303e730a41ad32e72af91353894125d5d5e22ab82cbded6abc98715f6ce63

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

require File.dirname(__FILE__) + '/test_helper.rb'
require 'application_controller'
require 'action_controller/test_process'

class ApplicationController
  def rescue_action(e)
    raise e
  end

  # Returns id of hypothetical current user
  def current_user
    153
  end
end

class WidgetsController < ApplicationController
  def create
    @widget = Widget.create params[:widget]
    head :ok
  end

  def update
    @widget = Widget.find params[:id]
    @widget.update_attributes params[:widget]
    head :ok
  end

  def destroy
    @widget = Widget.find params[:id]
    @widget.destroy
    head :ok
  end
end


class PaperTrailControllerTest < ActionController::TestCase #Test::Unit::TestCase
  def setup
    @controller = WidgetsController.new
    @request = ActionController::TestRequest.new
    @response = ActionController::TestResponse.new

    ActionController::Routing::Routes.draw do |map|
      map.resources :widgets
    end
  end

  test 'create' do
    post :create, :widget => { :name => 'Flugel' }
    widget = assigns(:widget)
    assert_equal 1, widget.versions.length
    assert_equal 153, widget.versions.last.whodunnit.to_i
  end

  test 'update' do
    w = Widget.create :name => 'Duvel'
    assert_equal 1, w.versions.length
    put :update, :id => w.id, :widget => { :name => 'Bugle' }
    widget = assigns(:widget)
    assert_equal 2, widget.versions.length
    assert_equal 153, widget.versions.last.whodunnit.to_i
  end

  test 'destroy' do
    w = Widget.create :name => 'Roundel'
    assert_equal 1, w.versions.length
    delete :destroy, :id => w.id
    widget = assigns(:widget)
    assert_equal 2, widget.versions.length
    assert_equal 153, widget.versions.last.whodunnit.to_i
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
airblade-paper_trail-1.0.1 test/paper_trail_controller_test.rb
airblade-paper_trail-1.1.0 test/paper_trail_controller_test.rb
airblade-paper_trail-1.1.1 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.10 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.12 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.2 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.3 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.5 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.6 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.7 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.8 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.9 test/paper_trail_controller_test.rb
jeremyw-paper_trail-1.2.14 test/paper_trail_controller_test.rb
paper_trail-1.2.14 test/paper_trail_controller_test.rb
paper_trail-1.2.13 test/paper_trail_controller_test.rb