Sha256: 88e487237e339a4e360f7e224eb3b3b7151a52b87a30fbf88e1302326167ada7

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

module FriendlyId

  # A Shoulda[http://www.thoughtbot.com/projects/shoulda/] macros for testing
  # models using FriendlyId.
  module ShouldaMacros

    # Ensure that a model is using FriendlyId.
    def self.should_have_friendly_id(column, options = {})

      options.assert_valid_keys(:use_slug)
      klass = self.model_class

      should "have friendly id for #{method}" do
        assert_respond_to klass, :friendly_id_options,
          "#{klass} does not respond to friendly_id_options"
        assert_equal column, klass.friendly_id_options[:method]
      end

      if options[:use_slug]
        should "include/extend friendly_id's sluggable modules" do
          assert klass.extended_by.include?(FriendlyId::SluggableClassMethods),
            "#{klass} does not extend FriendlyId::SluggableClassMethods"
          assert klass.include?(FriendlyId::SluggableInstanceMethods),
            "#{klass} not include FriendlyId::SluggableInstanceMethods"
        end
      else
        should "include/extend friendly_id's non-sluggable modules" do
          assert klass.extended_by.include?(FriendlyId::NonSluggableClassMethods),
            "#{klass} does not extend FriendlyId::NonSluggableClassMethods"
          assert klass.include?(FriendlyId::NonSluggableInstanceMethods),
            "#{klass} not include FriendlyId::NonSluggableInstanceMethods"
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
dougcole-friendly_id-2.0.2 lib/friendly_id/shoulda_macros.rb
dougcole-friendly_id-2.0.3 lib/friendly_id/shoulda_macros.rb
dougcole-friendly_id-2.0.4 lib/friendly_id/shoulda_macros.rb
dougcole-friendly_id-2.0.5 lib/friendly_id/shoulda_macros.rb
norman-friendly_id-2.0.1 lib/friendly_id/shoulda_macros.rb
norman-friendly_id-2.0.2 lib/friendly_id/shoulda_macros.rb
alancse-friendly_id-2.0.1 lib/friendly_id/shoulda_macros.rb
friendly_id-1.9.9 lib/friendly_id/shoulda_macros.rb
friendly_id-2.0.1 lib/friendly_id/shoulda_macros.rb
friendly_id-2.0.0 lib/friendly_id/shoulda_macros.rb