class Adapter::ActiveModel::Resource
Attributes
options[R]
Public Class Methods
new(options, response, _binding)
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 5 def initialize(options, response, _binding) @options = HashWithIndifferentAccess.new(options) @response = response @_binding = _binding end
Public Instance Methods
compare_attribute(attribute)
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 17 def compare_attribute(attribute) expect(resource.send(attribute)).to( eql( modifier_for(attribute).call( model.send(attribute) ) ) ) end
embedded_collection(new_options = {})
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 27 def embedded_collection(new_options = {}) raise 'embeds option missing' unless (options[:embeds] || new_options[:embeds]) Adapter::ActiveModel::Collection.new( options.merge(new_options), resource.send(options[:embeds]), @_binding ) end
has_attribute(attribute)
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 39 def has_attribute(attribute) expect(resource.send(attribute)).to_not(eql(:attribute_not_found)) end
has_no_attribute(attribute)
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 35 def has_no_attribute(attribute) expect(resource.send(attribute)).to(eql(:attribute_not_found)) end
resource()
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 11 def resource @resource ||= objectize_resource( @response, root: options[:resource], existing: options[:existing] ) end
Private Instance Methods
attrs()
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 54 def attrs options[:attrs].map{|i| i.to_s} end
attrs?()
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 58 def attrs? attrs.any? end
model()
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 46 def model raise 'model is missing' if options[:model].blank? @model ||= parse_model( @_binding.instance_exec(&options[:model]) ) end
modifiers_hash()
click to toggle source
# File lib/rspec/api_helpers/adapter/active_model/resource.rb, line 62 def modifiers_hash return {} if options[:modifiers].blank? @modifiers_hash = HashWithIndifferentAccess.new({}) options[:modifiers].each do |key, value| [key].flatten.each do |attr| if attrs? raise "#{attr} missing from :attrs param" unless attrs.include?(attr.to_s) @modifiers_hash[attr] = value end end end return @modifiers_hash end