Sha256: 3134d5814568c7b46ac32bdbf174d7c58eafb2b40791da7d2ac62e109049b15b
Contents?: true
Size: 1.11 KB
Versions: 5
Compression:
Stored size: 1.11 KB
Contents
# Generate model specs. require 'katapult/generator' module Katapult module Generators class ModelSpecsGenerator < Katapult::Generator desc 'Generate model specs' check_class_collision source_root File.expand_path('../templates', __FILE__) def create_model_spec template 'model_spec.rb', File.join('spec', 'models', "#{file_name}_spec.rb") end no_tasks do def specable_attrs model.attrs.select do |attr| attr.assignable_values.present? or attr.default != nil end end def assignable_value_for(attr) attr.assignable_values.last end # Guess a value that is not assignable def unassignable_value_for(attr) case attr.type when :integer attr.assignable_values.max + 1 when :string assignable_value_for(attr) + '-unassignable' else raise "Assignable values for :#{attr.type} attributes not supported" end end end private def model @element end end end end
Version data entries
5 entries across 5 versions & 1 rubygems