Module: PgAuditLogSpecHelper::InstanceMethods
- Defined in:
- lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb
Instance Method Summary collapse
- #create_object_for_klass(klass, exclude_columns = []) ⇒ Object
- #get_data(column, format_without_timezone = false) ⇒ Object
- #get_diff_data(column, format_without_timezone = false) ⇒ Object
Instance Method Details
#create_object_for_klass(klass, exclude_columns = []) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb', line 91 def create_object_for_klass(klass, exclude_columns = []) exclude_columns = exclude_columns | EXCLUDED_COLUMNS object = klass.new columns = klass.columns.reject {|column| exclude_columns.include? column.name } columns.each do |column| object.send("#{column.name}=", get_data(column)) end object.send(:create_without_callbacks) [object, columns] end |
#get_data(column, format_without_timezone = false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb', line 28 def get_data(column, format_without_timezone = false) case column.type when :boolean true when :date Date.parse("1/1/2000") when :datetime if format_without_timezone DateTime.parse("1/1/2000 1pm").utc.strftime("%Y-%m-%d %H:%M:%S") else DateTime.parse("1/1/2000 1pm").utc.to_s end when :integer 7 when :decimal "7.1234567891" when :float 7.1234 when :string if column.name == "type" "Object" else "Happy" end when :text "Happy text" else raise "I don't know how to make data for '#{column.type}'!" end end |
#get_diff_data(column, format_without_timezone = false) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb', line 60 def get_diff_data(column, format_without_timezone = false) case column.type when :boolean false when :date Date.parse("12/1/2000") when :datetime if format_without_timezone DateTime.parse("12/1/2000 1pm").utc.strftime("%Y-%m-%d %H:%M:%S") else DateTime.parse("12/1/2000 1pm").utc.to_s end when :integer 9 when :decimal "9.1234567891" when :float 9.1234 when :string if column.name == "type" "Object" else "Sad" end when :text "Sad text" else raise "I don't know how to make data for '#{column.type}'!" end end |