module QuickShoulda::Generator::Association

Constants

MappedMacros
OptionMethods
SingleQuoteMethods

Public Instance Methods

generate_associations(model) click to toggle source
# File lib/quick_shoulda/generator/association.rb, line 23
def generate_associations(model)
  model.reflect_on_all_associations.map { |association| generate_for_association(association) }.compact.flatten
end

Private Instance Methods

generate_for_association(association) click to toggle source
# File lib/quick_shoulda/generator/association.rb, line 29
def generate_for_association(association)
  shoulda_method_name = MappedMacros[association.macro.to_sym]
  "it { should #{shoulda_method_name}(:#{association.name})#{shoulda_assciation_option_methods_chain(association.options)} }"
end
shoulda_assciation_option_methods_chain(options) click to toggle source
# File lib/quick_shoulda/generator/association.rb, line 34
def shoulda_assciation_option_methods_chain(options)
  options.map do |option, value|
    shoulda_option_method_with_value(option, value)
  end.compact.join
end
shoulda_option_method_with_value(option, value) click to toggle source
# File lib/quick_shoulda/generator/association.rb, line 40
def shoulda_option_method_with_value(option, value)    
  method_name = OptionMethods[option.to_sym]          
  ".#{method_name}#{value_transform(value)}" if method_name
end