Sha256: 090f4968d7e85895e9bb96eca28082805a490b876493816f2faca94f5df8b9a0

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

module RSpecCandy
  module Helpers
    module Rails
      module StoreWithValues

        def store_with_values(values = {})
          record = new
          if Switcher.rails_version == :rails2
            record.send(:attributes=, values, false)
            record.send(:create_without_callbacks)
          else
            require 'sneaky-save'
            record.assign_attributes(values, :without_protection => true)
            record.sneaky_save
          end
          record
        end

        def new_and_store(*args)
          warn 'new_and_store is deprecated. Use store_with_values instead.'
          store_with_values(*args)
        end

        def create_without_callbacks(*args)
          warn 'create_without_callbacks is deprecated because the name suggested that it honors mass-assignment protection. Use store_with_values instead.'
          store_with_values(*args)
        end

        ActiveRecord::Base.send(:extend, self)

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec_candy-0.3.1 lib/rspec_candy/helpers/rails/store_with_values.rb
rspec_candy-0.3.0 lib/rspec_candy/helpers/rails/store_with_values.rb
rspec_candy-0.2.10 lib/rspec_candy/helpers/rails/store_with_values.rb
rspec_candy-0.2.9 lib/rspec_candy/helpers/rails/store_with_values.rb
rspec_candy-0.2.8 lib/rspec_candy/helpers/rails/store_with_values.rb