Class: Rails::Generator::GeneratedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/rspec-rails/generators/rspec_default_values.rb,
lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb

Instance Method Summary collapse

Instance Method Details

#default_valueObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_default_values.rb', line 4

def default_value
  @default_value ||= case type
    when :int, :integer               then "1"
    when :float                       then "1.5"
    when :decimal                     then "9.99"
    when :datetime, :timestamp, :time then "Time.now"
    when :date                        then "Date.today"
    when :string, :text               then "\"value for #{@name}\""
    when :boolean                     then "false"
    when :belongs_to, :references     then "1"
    else
      ""
  end
end

#input_typeObject



145
146
147
148
149
150
151
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb', line 145

def input_type
  @input_type ||= case type
    when :text                        then "textarea"
    else
      "input"
  end      
end

#name_or_referenceObject



19
20
21
22
23
24
25
# File 'lib/vendor/plugins/rspec-rails/generators/rspec_default_values.rb', line 19

def name_or_reference
  if ::Rails::VERSION::STRING >= '2.2'
    reference? ? :"#{name}_id" : name
  else
    name
  end
end