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
  Pathname.new('/tmp/adva-static-test/export')
end

#futureObject



134
135
136
# File 'lib/testing/test_helper.rb', line 134

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
  Adva::Static::Import::Source::Path.new('/tmp/adva-static-test/import')
end

#setupObject



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

def setup
  import_dir.mkpath
  super
end

#setup_dirs(paths) ⇒ Object



121
122
123
# File 'lib/testing/test_helper.rb', line 121

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

#setup_file(path, content = '') ⇒ Object



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

def setup_file(path, content = '')
  import_dir.join(File.dirname(path)).mkpath
  File.open(import_dir.join(path), 'w') { |f| f.write(content) }
end

#setup_files(*files) ⇒ Object



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

def setup_files(*files)
  files.each { |path, content| setup_file(path, content) }
end

#setup_import_directoryObject



64
65
66
67
68
# File 'lib/testing/test_helper.rb', line 64

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



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

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

#setup_non_root_blogObject



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

def setup_non_root_blog
  setup_files(
    ['blog/2010/10/10/post.yml', YAML.dump(:filter => 'markdown', :body => 'body', :categories => 'foo, bar')],
    ['blog/2010/10/09/hello-world.yml', YAML.dump(:filter => 'markdown', :body => 'hello world!')]
  )
end

#setup_non_root_blog_recordObject



59
60
61
62
# 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 => 'Post', :body => 'body', :published_at => '2010-10-10' }])
end

#setup_non_root_nested_pageObject



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

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

#setup_non_root_pageObject



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

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

#setup_non_root_page_recordObject



47
48
49
50
# File 'lib/testing/test_helper.rb', line 47

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

#setup_root_blogObject



77
78
79
80
81
82
# File 'lib/testing/test_helper.rb', line 77

def setup_root_blog
  setup_files(
    ['2010/10/10/post.yml', YAML.dump(:filter => 'markdown', :body => 'body', :categories => 'foo, bar')],
    ['2010/10/09/hello-world.yml', YAML.dump(:filter => 'markdown', :body => 'hello world!')]
  )
end

#setup_root_blog_recordObject



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

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

  site.blogs.create!(:name => 'Home', :posts_attributes => [{ :title => 'Post', :body => 'body', :published_at => '2010-10-10' }])
end

#setup_root_nested_pageObject



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

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

#setup_root_pageObject



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

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

#setup_root_page_recordObject



43
44
45
# File 'lib/testing/test_helper.rb', line 43

def setup_root_page_record
  Site.first || setup_site_record
end

#setup_siteObject



70
71
72
73
74
75
# File 'lib/testing/test_helper.rb', line 70

def setup_site
  import_dir.mkpath
  setup_files(
    ['site.yml', YAML.dump(:host => 'ruby-i18n.org', :name => 'name', :title => 'title')]
  )
end

#setup_site_recordObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/testing/test_helper.rb', line 29

def setup_site_record
  Factory(:site, :host => 'ruby-i18n.org').tap do |site|
    # FIXME this stinks. make static export authentication possible without saving the password anywhere.
    #
    # because the password for the admin is hardcoded in adva-static//request
    # and the admin is created automatically with a different password we
    # have to override this here
    admin = User.find_by_email( '[email protected]' )
    admin.password = 'admin!'
    admin.password_confirmation = 'admin!'
    admin.save!
  end
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