module JsonVoorhees class AppMakeTestsGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) argument :module_name, :type => :string argument :resource_name, :type => :string argument :api_version, :type => :string, :default => "1" argument :attributes, type: :array, default: [], banner: "field:type field:type" class_option :fbonly, :type => :boolean, :default => false, :description => "Use facebook login?" def sprint template "model.rb.erb", "spec/engines/#{module_snake}/api/v#{api_version}/models/#{resource_singular}_spec.rb" template "routing.rb.erb", "spec/engines/#{module_snake}/api/v#{api_version}/routing/#{resource_singular}_spec.rb" template "factory.rb.erb", "spec/factories/#{module_snake}_#{resource_singular}_#{api_version}_factory.rb" requests end private def requests if options.fbonly? template "fbonly_request.rb.erb", "spec/engines/#{module_snake}/api/v#{api_version}/requests/#{resource_singular}_spec.rb" else template "request.rb.erb", "spec/engines/#{module_snake}/api/v#{api_version}/requests/#{resource_singular}_spec.rb" end end def default_values(field1) field = field1.downcase if field == "integer" return 1 end if field == "boolean" return true end if field == "string" return "\"Default String\"" end if field == "text" return "\"Default Text\"" end if field == "float" return 3.14 end if field == "decimal" return 3.14159 end if field == "date" return "\"#{Date.new}\"" end if field == "time" return "\"#{Time.new}\"" end if field == "datetime" return "\"#{DateTime.new}\"" end #If there are any values that I missed return nil end def resource_singular resource_name.underscore.singularize end def resource_plural resource_name.underscore.pluralize end def resource_camel resource_name.camelize.singularize end def module_camel module_name.camelize end def module_snake module_name.underscore.downcase end end end