diff options
| -rw-r--r-- | app/controllers/snapshots_controller.rb | 14 | ||||
| -rw-r--r-- | app/views/layouts/snapshots/actions_links.html.slim | 21 | ||||
| -rw-r--r-- | app/views/layouts/snapshots/default.html.slim | 19 | ||||
| -rw-r--r-- | config/routes.rb | 4 | ||||
| -rw-r--r-- | spec/support/snapshot_support.rb | 15 |
5 files changed, 72 insertions, 1 deletions
diff --git a/app/controllers/snapshots_controller.rb b/app/controllers/snapshots_controller.rb new file mode 100644 index 000000000..e453b4965 --- /dev/null +++ b/app/controllers/snapshots_controller.rb @@ -0,0 +1,14 @@ +class SnapshotsController < ApplicationController + if Rails.env.development? || Rails.env.test? + layout :which_layout + def show + tpl = params[:snap] + tpl = tpl.gsub Rails.root.to_s, '' + render file: tpl + end + + def which_layout + "snapshots/#{params[:layout] || "default"}" + end + end +end diff --git a/app/views/layouts/snapshots/actions_links.html.slim b/app/views/layouts/snapshots/actions_links.html.slim new file mode 100644 index 000000000..f1fa55e87 --- /dev/null +++ b/app/views/layouts/snapshots/actions_links.html.slim @@ -0,0 +1,21 @@ +doctype html +html lang=I18n.locale + head + meta charset="utf-8" + meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" + + = csrf_meta_tag + + title = t('brandname') + + = stylesheet_link_tag 'base' + = stylesheet_link_tag 'application' + + = javascript_pack_tag 'application' + = javascript_include_tag 'application' + + body + = render 'layouts/navigation/main_nav' + = render 'layouts/flash_messages', flash: flash + div.page_header + = yield diff --git a/app/views/layouts/snapshots/default.html.slim b/app/views/layouts/snapshots/default.html.slim new file mode 100644 index 000000000..9e4565dcb --- /dev/null +++ b/app/views/layouts/snapshots/default.html.slim @@ -0,0 +1,19 @@ +doctype html +html lang=I18n.locale + head + meta charset="utf-8" + meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" + + = csrf_meta_tag + + title = t('brandname') + + = stylesheet_link_tag 'base' + = stylesheet_link_tag 'application' + + = javascript_pack_tag 'application' + = javascript_include_tag 'application' + + body + = yield + diff --git a/config/routes.rb b/config/routes.rb index 5fc39ba92..2715ca428 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -241,6 +241,10 @@ ChouetteIhm::Application.routes.draw do root :to => "dashboards#show" + if Rails.env.development? || Rails.env.test? + get "/snap" => "snapshots#show" + end + get '/help/(*slug)' => 'help#show' if Rails.application.config.development_toolbar diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb index f1a6b1469..c37bb075c 100644 --- a/spec/support/snapshot_support.rb +++ b/spec/support/snapshot_support.rb @@ -6,14 +6,27 @@ RSpec::Matchers.define :match_actions_links_snapshot do |name| failure_message do |actual| out = ["Snapshots did not match."] - expected = File.read(File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap") + snap_path = File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap" + temp_path = Pathname.new "#{Rails.root}/tmp/__snapshots__/#{name}.failed.snap" + FileUtils.mkdir_p temp_path.dirname + tmp = File.new temp_path, "w" + tmp.write @content + tmp.close() + expected = File.read snap_path out << "Expected: #{expected}" out << "Actual: #{@content}" out << "\n\n --- DIFF ---" out << differ.diff_as_string(@content, expected) + out << "\n\n --- Previews : ---" + out << "Expected: \n" + snapshot_url(snap: snap_path, layout: :actions_links) + out << " \nActual: \n" + snapshot_url(snap: tmp.path, layout: :actions_links) out.join("\n") end + def snapshot_url snap:, layout: + "http://localhost:3000/snap/?snap=#{URI.encode(snap.to_s)}&layout=#{URI.encode(layout.to_s)}" + end + def differ RSpec::Support::Differ.new( :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) }, |
