Top Level Namespace

Defined Under Namespace

Modules: AbilityHelper, ActiveDisablable, ActiveMigration, ApplicationHelper, BusinessActivitiesHelper, BusinessDepartmentsHelper, BusinessSegmentsHelper, CompanyBusinessesHelper, ContactsHelper, CustomersHelper, EmailHelper, FormAjaxHelper, Guara, GuaraViewsHelper, LocaleHelper, MenuHelper, SessionsHelper, StringHelper, TasksHelper, Tests, UserAbilitiesHelper, UserType, UsersHelper Classes: AbilitiesController, Ability, Address, ApplicationController, BusinessActivitiesController, BusinessActivity, BusinessDepartment, BusinessDepartmentsController, BusinessSegment, BusinessSegmentsController, City, CompanyBusiness, CompanyBusinessesController, Contact, ContactsController, Customer, CustomerActivity, CustomerCnpjValidator, CustomerFinancial, CustomerHasCustomers, CustomerPf, CustomerPj, CustomerPjHasCustomersPj, CustomerProduct, CustomerSegment, CustomersController, District, Email, EmailValidator, FeedbacksController, Micropost, MicropostsController, Relationship, Search, SessionsController, State, StaticPagesController, SystemAbility, SystemModule, SystemTaskResolution, SystemTaskStatus, SystemTaskStatusController, Task, TaskFeedback, TaskType, TaskTypesController, TasksController, User, UserAbility, UserGroup, UsersController, UsersHasGroups

Instance Method Summary collapse

Instance Method Details

#build_migration_configObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/spec/support/active_migration_helper.rb', line 6

def build_migration_config()  
    # build schema from
    puts_on_file Rails.root.join("tmp/migration_schema.yml") do    
      {
        :from => {
           columns: { name: "string" },
          format: :XLS,
          url: File.expand_path("../../asserts/sheet1.xls", __FILE__)
        },
      
        :to => { columns:
            { name: "string" },
          format: :ACTIVE_RECORD,
          url: "District"
        }
      }.to_yaml
    end

end

#build_migration_schemas_configObject

Schemas



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/spec/support/active_migration_helper.rb', line 32

def build_migration_schemas_config()
  
  puts_on_file "tmp/file_existing.xls" do
    (1..5).map { |n| "line%d" % n }.join("\n")
  end
  
  puts_on_file Rails.root.join("tmp/schemas.yml") do
    
    { 
      "test" => {
        type: :CUSTOM,
        from: {
          columns: {
            name: "string"
          },
          format: :XLS,
          url: File.expand_path("../../asserts/sheet1.xls", __FILE__)
        },
        to: "District",
        transformer: "MigrationTestDistrictTransformer" 
      },
      
      "activities" => {
        type: :SCHEMA,
        from: {
          columns: {
            name: "string"
          },
          format: :XLS,
          url: File.expand_path("../../asserts/sheet1.xls", __FILE__)
        },
        to: {
            columns: {
              name: "string"
            },
            format: :ACTIVE_RECORD,
            url: "District"
        },
        transformer: "MigrationActivityTransformer"
      }
    }.to_yaml
    
  end
end

#build_schemas_tmp_classesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/spec/support/active_migration_helper.rb', line 77

def build_schemas_tmp_classes()
  eval %q{
    class MigrationTestDistrictTransformer
      include ActiveMigration::Transformer
      
      def initialize(schema)
        
      end
      
      def migrate!
        Rails.logger.info "called MigrationTestDistrictTransformer.migrate!"
        true
      end
      
    end
  }
  
  eval %q{
    class MigrationActivityTransformer
      include ActiveMigration::Transformer
      
      def initialize(schema)
        
      end
      
      def transform(row)
        row[:name] = row[:name] + Time.now.to_s
        true
      end
      
    end
  }
end

#config_transactional(config) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/spec/spec_helper.rb', line 21

def config_transactional(config)
  
  except_tables = %w[SystemAbility SystemModule SystemTaskStatus SystemTaskResolution State City BusinessSegment BusinessActivity].collect { |e| pluralize_without_count(2, e.underscore) }
  
  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction, {:except => except_tables}
    else
      DatabaseCleaner.strategy = :truncation, {:except => except_tables}
    end
    DatabaseCleaner.start
  end

  config.after :each do
    DatabaseCleaner.clean
  end
end

#puts_on_file(file, string = nil) ⇒ Object



2
3
4
5
6
7
# File 'lib/spec/support/utilities.rb', line 2

def puts_on_file(file, string=nil)
  string ||= yield
  aFile = File.new(file, "w")
  aFile.write(string)
  aFile.close
end