Sha256: 22973a8411800ca428aaac7046f3f65c54c8a089c1aba26bf2c4fa3af8f76c05

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require File.dirname(__FILE__) + '/test_helper'
class ActionControllerTest < Test::Unit::TestCase
  class ActionControllerMock
    def self.helper(args)
      @__helper = args
    end

    def self.helper_value
      @__helper
    end

    def self.before_filter(args)
      @__before_filter = args
    end

    def self.before_filter_value
      @__before_filter
    end

    extend TrackChanges::ActionController
  end


  def setup
    @action_controller = ActionControllerMock.new
  end

  def test_should_add_track_changes_class_method
    assert ActionControllerMock.respond_to?(:track_changes)
  end

  def test_should_set_a_before_filter
    ActionControllerMock.class_eval do
      track_changes :some_var
    end

    assert ActionControllerMock.before_filter_value.respond_to?(:filter)
  end

  def test_should_accept_multiple_arguments
    assert_nothing_raised do
      ActionControllerMock.class_eval do
        track_changes :foo
      end
      
      ActionControllerMock.class_eval do
        track_changes :foo, :bar
      end

      ActionControllerMock.class_eval do
        track_changes :foo, :bar, :baz
      end
    end
  end

  def test_should_define_a_method_that_returns_interested_vars
    ActionControllerMock.class_eval do
      track_changes :foo, :bar, :baz
    end

    interesting_vars = ActionControllerMock.new.__track_changes_to_models
    assert interesting_vars.include?(:foo), interesting_vars.inspect
    assert interesting_vars.include?(:bar), interesting_vars.inspect
    assert interesting_vars.include?(:baz), interesting_vars.inspect
  end

  def test_should_include_helpers
    ActionControllerMock.class_eval do
      track_changes :foo
    end

    assert_equal :audits, ActionControllerMock.helper_value
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
track_changes-1.0.1 test/action_controller_test.rb
track_changes-1.0.0 test/action_controller_test.rb