spec/support/helpers.rb
# Sets up attributes module with a listener to listen on reads/writes to the
# backend. Pass two separate arrays to create separate attributes modules.
Sets up attributes module with a listener to listen on reads/writes to the
backend. Pass two separate arrays to create separate attributes modules.
Sets up attributes module with a listener to listen on reads / writes to the backend . Pass two separate arrays to create separate attributes modules .
def plugin_setup(attribute_name = "title", *other_names, **options)
        plugins = options.keys & %i[query cache dirty fallbacks presence default attribute_methods fallthrough_accessors locale_accessors]
        attribute_names = [attribute_name, *other_names]
        let(:attribute_name) { attribute_name }
        let(:attributes_class) do
          Class.new(TestAttributes).tap do |attrs|
            plugins.each { |plugin| attrs.plugin plugin }
          end
        end
        let(:model_class) do
          Class.new.tap do |klass|
            klass.include attributes
          end
        end
        let(:instance) { model_class.new }
        let(:attributes) { attributes_class.new(*attribute_names, backend: backend_class, **options) }
        let(:listener) { double(:backend) }
        let(:backend_class) { backend_listener(listener) }
        let(:backend) { instance.send("#{attribute_name}_backend") }
        attribute_names.each { |name| let(:"#{name}_backend") { instance.send("#{name}_backend") } }
      end
def plugin_setup ( attribute_name = "title" , * other_names , ** options ) plugins = options . keys & %i[ query cache dirty fallbacks presence default attribute_methods fallthrough_accessors locale_accessors ] attribute_names = [ attribute_name , * other_names ] let ( :attribute_name ) { attribute_name } let ( :attributes_class ) do Class . new ( TestAttributes ) . tap do | attrs | plugins . each { | plugin | attrs . plugin plugin } end end let ( :model_class ) do Class . new . tap do | klass | klass . include attributes end end let ( :instance ) { model_class . new } let ( :attributes ) { attributes_class . new ( * attribute_names , backend : backend_class , ** options ) } let ( :listener ) { double ( :backend ) } let ( :backend_class ) { backend_listener ( listener ) } let ( :backend ) { instance . send ( "#{attribute_name}_backend" ) } attribute_names . each { | name | let ( :" #{ name } _backend " ) { instance . send ( "#{name}_backend" ) } } end
Sets up attributes module with a listener to listen on reads/writes to the
backend.
Sets up attributes module with a listener to listen on reads / writes to the backend .
attribute_name
<not_specific>
other_names
<not_specific>
options
<not_specific>