Module: TestHelper::Static

Defined in:
lib/testing/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#export_dirObject



20
21
22
# File 'lib/testing/test_helper.rb', line 20

def export_dir
  @export_dir ||= Pathname.new('/tmp/adva-static-test/export')
end

#futureObject



129
130
131
# File 'lib/testing/test_helper.rb', line 129

def future
  Time.local(Time.now.year + 1, Time.now.month, Time.now.day)
end

#import_dirObject



16
17
18
# File 'lib/testing/test_helper.rb', line 16

def import_dir
  @import_dir ||= Pathname.new('/tmp/adva-static-test/import/ruby-i18n.org')
end

#request(path) ⇒ Object



29
30
31
# File 'lib/testing/test_helper.rb', line 29

def request(path)
  Adva::Static::Import.new(:source => import_dir).request_for(path)
end

#setupObject



3
4
5
6
# File 'lib/testing/test_helper.rb', line 3

def setup
  setup_import_directory
  super
end

#setup_dirs(paths) ⇒ Object



116
117
118
119
120
# File 'lib/testing/test_helper.rb', line 116

def setup_dirs(paths)
  paths.each do |path|
    FileUtils.mkdir_p(import_dir.join(path))
  end
end

#setup_files(*files) ⇒ Object



122
123
124
125
126
127
# File 'lib/testing/test_helper.rb', line 122

def setup_files(*files)
  files.each do |path, content|
    import_dir.join(File.dirname(path)).mkpath
    File.open(import_dir.join(path), 'w') { |f| f.write(content) }
  end
end

#setup_import_directoryObject



66
67
68
69
70
# File 'lib/testing/test_helper.rb', line 66

def setup_import_directory
  import_dir.mkpath
  setup_dirs(%w(images javascripts stylesheets))
  setup_files(['config.ru', 'foo'], ['site.yml', YAML.dump(:host => 'ruby-i18n.org', :name => 'Ruby I18n', :title => 'Ruby I18n')])
end

#setup_nested_pageObject



110
111
112
113
114
# File 'lib/testing/test_helper.rb', line 110

def setup_nested_page
  setup_files(
    ['contact/mailer.yml', YAML.dump(:body => 'contact mailer')]
  )
end

#setup_non_root_blogObject



79
80
81
82
83
84
# File 'lib/testing/test_helper.rb', line 79

def setup_non_root_blog
  setup_files(
    ['blog/2008/07/31/welcome-to-the-future-of-i18n-in-ruby-on-rails.yml', YAML.dump(:body => 'Welcome to the future')],
    ['blog/2009/07/12/ruby-i18n-gem-hits-0-2-0.yml', YAML.dump(:body => 'Ruby I18n hits 0.2.0')]
  )
end

#setup_non_root_blog_recordObject



59
60
61
62
63
64
# File 'lib/testing/test_helper.rb', line 59

def setup_non_root_blog_record
  site = setup_site_record
  site.blogs.create!(:name => 'Blog', :posts_attributes => [
    { :title => 'Welcome to the future of I18n in Ruby on Rails', :body => 'Welcome to the future!', :published_at => '2008-07-31' }
  ])
end

#setup_non_root_nested_pageObject



104
105
106
107
108
# File 'lib/testing/test_helper.rb', line 104

def setup_non_root_nested_page
  setup_files(
    ['contact/nested.yml', YAML.dump(:body => 'nested under contact')]
  )
end

#setup_non_root_pageObject



98
99
100
101
102
# File 'lib/testing/test_helper.rb', line 98

def setup_non_root_page
  setup_files(
    ['contact.yml', YAML.dump(:body => 'contact')]
  )
end

#setup_non_root_page_recordObject



45
46
47
48
# File 'lib/testing/test_helper.rb', line 45

def setup_non_root_page_record
  site = setup_site_record
  site.pages.create!(:name => 'Contact')
end

#setup_root_blogObject



72
73
74
75
76
77
# File 'lib/testing/test_helper.rb', line 72

def setup_root_blog
  setup_files(
    ['2008/07/31/welcome-to-the-future-of-i18n-in-ruby-on-rails.yml', YAML.dump(:body => 'Welcome to the future')],
    ['2009/07/12/ruby-i18n-gem-hits-0-2-0.yml', YAML.dump(:body => 'Ruby I18n hits 0.2.0')]
  )
end

#setup_root_blog_recordObject



50
51
52
53
54
55
56
57
# File 'lib/testing/test_helper.rb', line 50

def setup_root_blog_record
  site = setup_site_record
  site.pages.first.destroy

  site.blogs.create!(:name => 'Home', :posts_attributes => [
    { :title => 'Welcome to the future of I18n in Ruby on Rails', :body => 'Welcome to the future!', :published_at => '2008-07-31' }
  ])
end

#setup_root_nested_pageObject



92
93
94
95
96
# File 'lib/testing/test_helper.rb', line 92

def setup_root_nested_page
  setup_files(
    ['home/nested.yml', YAML.dump(:body => 'nested under home')]
  )
end

#setup_root_pageObject



86
87
88
89
90
# File 'lib/testing/test_helper.rb', line 86

def setup_root_page
  setup_files(
    ['index.yml', YAML.dump(:name => 'Home', :body => 'home')]
  )
end

#setup_root_page_recordObject



41
42
43
# File 'lib/testing/test_helper.rb', line 41

def setup_root_page_record
  setup_site_record
end

#setup_site_recordObject



37
38
39
# File 'lib/testing/test_helper.rb', line 37

def setup_site_record
  Factory(:site, :host => 'ruby-i18n.org')
end

#source(path) ⇒ Object



33
34
35
# File 'lib/testing/test_helper.rb', line 33

def source(path)
  Adva::Static::Import::Source.new(path, import_dir)
end

#teardownObject



24
25
26
27
# File 'lib/testing/test_helper.rb', line 24

def teardown
  teardown_import_directory
  super
end

#teardown_export_directoryObject



12
13
14
# File 'lib/testing/test_helper.rb', line 12

def teardown_export_directory
  export_dir.rmtree rescue nil
end

#teardown_import_directoryObject



8
9
10
# File 'lib/testing/test_helper.rb', line 8

def teardown_import_directory
  import_dir.rmtree rescue nil
end