Sha256: b4efa194c8248c37417ccf7b25acbc96cb12d0998841f557c2eafbf0ffbf9420

Contents?: true

Size: 1008 Bytes

Versions: 4

Compression:

Stored size: 1008 Bytes

Contents

require 'helper'

describe Toy::Plugins do
  uses_constants('User', 'Game')

  it "keeps track of class that include toy store" do
    Toy.models.should == [User, Game]
  end

  describe ".plugin" do
    before do
      class_methods_mod    = Module.new { def foo; 'foo' end }
      instance_methods_mod = Module.new { def bar; 'bar' end }

      @mod = Module.new { extend ActiveSupport::Concern }
      @mod.const_set(:ClassMethods,    class_methods_mod)
      @mod.const_set(:InstanceMethods, instance_methods_mod)

      Toy.plugin(@mod)
    end

    it "includes module in all models" do
      [User, Game].each do |model|
        model.foo.should     == 'foo'
        model.new.bar.should == 'bar'
      end
    end

    it "adds plugin to plugins" do
      Toy.plugins.should == [@mod]
    end

    it "adds plugins to classes declared after plugin was called" do
      klass = Class.new { include Toy::Store }
      klass.foo.should     == 'foo'
      klass.new.bar.should == 'bar'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
toystore-0.10.3 spec/toy/plugins_spec.rb
toystore-0.10.2 spec/toy/plugins_spec.rb
toystore-0.10.1 spec/toy/plugins_spec.rb
toystore-0.10.0 spec/toy/plugins_spec.rb