diff --git a/models/site.rb b/models/site.rb index 21db0433..28bcc2e4 100644 --- a/models/site.rb +++ b/models/site.rb @@ -296,12 +296,24 @@ class Site < Sequel::Model FileUtils.mkdir_p files_path %w{index not_found}.each do |name| - File.write files_path("#{name}.html"), render_template("#{name}.erb") + tmpfile = Tempfile.new "newinstall-#{name}" + tmpfile.write render_template("#{name}.erb") + tmpfile.close + + store_file "#{name}.html", tmpfile, new_install: true purge_cache "/#{name}.html" ScreenshotWorker.perform_async values[:username], "#{name}.html" end - FileUtils.cp template_file_path('cat.png'), files_path('cat.png') + tmpfile = Tempfile.new 'style.css' + tmpfile.close + FileUtils.cp template_file_path('style.css'), tmpfile.path + store_file 'style.css', tmpfile, new_install: true + + tmpfile = Tempfile.new 'cat.png' + tmpfile.close + FileUtils.cp template_file_path('cat.png'), tmpfile.path + store_file 'cat.png', tmpfile, new_install: true end def get_file(path) @@ -451,7 +463,7 @@ class Site < Sequel::Model PurgeCacheWorker.perform_async payload end - def store_file(path, uploaded) + def store_file(path, uploaded, opts={}) relative_path = scrubbed_path path path = files_path path @@ -486,7 +498,8 @@ class Site < Sequel::Model end pathname = Pathname(path) - if pathname.basename.to_s == 'index.html' + + if pathname.basename.to_s == 'index.html' && opts[:new_install] != true begin new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text rescue NoMethodError => e @@ -533,7 +546,7 @@ class Site < Sequel::Model ThumbnailWorker.perform_async values[:username], relative_path end - SiteChange.record self, relative_path + SiteChange.record self, relative_path unless opts[:new_install] true end diff --git a/tests/acceptance/signup_tests.rb b/tests/acceptance/signup_tests.rb index f29eddc6..9eff5628 100644 --- a/tests/acceptance/signup_tests.rb +++ b/tests/acceptance/signup_tests.rb @@ -38,10 +38,16 @@ describe 'signup' do fill_in_valid click_signup_button site_created?.must_equal true + assert_equal( true, File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html')) ) + + site = Site[username: @site[:username]] + site.site_files.length.must_equal 4 + site.site_changed.must_equal false + site.site_updated_at.must_equal nil end it 'fails to create for existing site' do diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index 76e0a2ed..62ed59ca 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -72,8 +72,8 @@ describe 'site_files' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg') last_response.body.must_match /successfully uploaded/i @site.reload.changed_count.must_equal 2 - @site.site_files.count.must_equal 1 - digest.wont_equal @site.reload.site_files.first.sha1_hash + @site.site_files.select {|f| f.path == 'test.jpg'}.length.must_equal 1 + digest.wont_equal @site.site_files_dataset.where(path: 'test.jpg').first.sha1_hash end it 'works with directory path' do diff --git a/views/templates/index.erb b/views/templates/index.erb index d7f350e7..1ffb0b31 100644 --- a/views/templates/index.erb +++ b/views/templates/index.erb @@ -3,16 +3,12 @@
Here's how you can make bold and italic text.
Here's how you can add an image:
-Here's how to make a list:
diff --git a/views/templates/not_found.erb b/views/templates/not_found.erb index dc6a06c8..2ed111e2 100644 --- a/views/templates/not_found.erb +++ b/views/templates/not_found.erb @@ -3,11 +3,7 @@