Module: AuthorizedRailsScaffolds::Macros::FactoryMacros

Included in:
RSpecIntegrationHelper, RSpecScaffoldControllerHelper, RSpecScaffoldViewHelper
Defined in:
lib/authorized_rails_scaffolds/macros/factory_macros.rb

Instance Method Summary collapse

Instance Method Details

#create_parent_resource_from_factory(parent_table_name) ⇒ Object



41
42
43
44
# File 'lib/authorized_rails_scaffolds/macros/factory_macros.rb', line 41

def create_parent_resource_from_factory(parent_table_name)
  extra_factory_params = build_extra_factory_params(parent_table_name)
  "FactoryGirl.create(:#{parent_table_name}#{extra_factory_params})"
end

#create_resource_from_factoryObject



36
37
38
39
# File 'lib/authorized_rails_scaffolds/macros/factory_macros.rb', line 36

def create_resource_from_factory
  extra_factory_params = build_extra_factory_params
  "FactoryGirl.create(#{resource_symbol}#{extra_factory_params})"
end

#factory_attribute_string(attribute_type, attribute_value) ⇒ Object

Returns the expected output string of attribute_value if it is an attribute_type



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/authorized_rails_scaffolds/macros/factory_macros.rb', line 20

def factory_attribute_string(attribute_type, attribute_value)
  case attribute_type
  when :datetime
    attribute_value_as_date = DateTime.parse(attribute_value)
    I18n.l(attribute_value_as_date, :format => :long).dump
  when :time
    attribute_value_as_time = Time.parse(attribute_value)
    I18n.l(attribute_value_as_time, :format => :short).dump
  when :date
    attribute_value_as_date = Date.parse(attribute_value)
    I18n.l(attribute_value_as_date).dump
  else
    attribute_value
  end
end

#factory_attribute_value(attribute_type, attribute_value) ⇒ Object

Returns code that will generate attribute_value as an attribute_type



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/authorized_rails_scaffolds/macros/factory_macros.rb', line 4

def factory_attribute_value(attribute_type, attribute_value)
  case attribute_type
  when :datetime
    "DateTime.parse(#{attribute_value})"
  when :time
    value_as_time = attribute_value.to_time.strftime('%T')
    "Time.parse(#{value_as_time.dump})"
  when :date
    value_as_date = attribute_value.to_time.strftime('%Y-%m-%d')
    "Date.parse(#{value_as_date.dump})"
  else
    attribute_value
  end
end