From 726e910ff4375fba9161baf8b33c685774c0f25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B3=A5=E4=BA=95=20=E9=9B=AA?= Date: Wed, 4 Feb 2015 16:52:35 +0900 Subject: [PATCH] Change not to show source when There is no difference between config files --- app/assets/stylesheets/common.css.scss | 8 +++++ .../concerns/setting_history_concern.rb | 5 ++- app/views/shared/settings/_diff.html.erb | 34 +++++++++++-------- config/locales/translation_en.yml | 1 + config/locales/translation_ja.yml | 1 + .../fluentd/setting/histories_spec.rb | 27 +++++++++++---- .../fluentd/setting/running_backup_spec.rb | 25 +++++++++++--- 7 files changed, 75 insertions(+), 26 deletions(-) diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index 654efa5..9957e74 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -177,3 +177,11 @@ label { background-color: #dfd; } } + +.frame-corner-radius { + border: 1px solid #ddd; + padding:10px 10px; + border-radius: 3px; + margin: 10px 0px; +} + diff --git a/app/controllers/concerns/setting_history_concern.rb b/app/controllers/concerns/setting_history_concern.rb index 6e4796e..49dd440 100644 --- a/app/controllers/concerns/setting_history_concern.rb +++ b/app/controllers/concerns/setting_history_concern.rb @@ -10,7 +10,10 @@ module SettingHistoryConcern def show current = @fluentd.agent.config target = @backup_file.content - @sdiff = Diff::LCS.sdiff(current.split("\n").map(&:rstrip), target.split("\n").map(&:rstrip)) if target + if target + @sdiff = Diff::LCS.sdiff(current.split("\n").map(&:rstrip), target.split("\n").map(&:rstrip)) + @changed = @sdiff.any? { |context_change| context_change.changed? } + end end def reuse diff --git a/app/views/shared/settings/_diff.html.erb b/app/views/shared/settings/_diff.html.erb index 0015e2b..1870f88 100644 --- a/app/views/shared/settings/_diff.html.erb +++ b/app/views/shared/settings/_diff.html.erb @@ -1,15 +1,21 @@ -
-<% @sdiff.each do |diff| %>
-<% case diff.action %>
-<% when "=" %>
-<%= diff.new_element %>
-<% when "!" %>
-- <%= diff.old_element %>
-+ <%= diff.new_element %>
-<% when "-" %>
-- <%= diff.old_element %>
-<% when "+" %>
-+ <%= diff.new_element %>
+<% if @changed %>
+  
+  <% @sdiff.each do |diff| %>
+  <% case diff.action %>
+  <% when "=" %>
+  <%= diff.new_element %>
+  <% when "!" %>
+  - <%= diff.old_element %>
+  + <%= diff.new_element %>
+  <% when "-" %>
+  - <%= diff.old_element %>
+  <% when "+" %>
+  + <%= diff.new_element %>
+  <% end %>
+  <% end %>
+  
+<% else %> +
+ <%= t('messages.no_diff') %> +
<% end %> -<% end %> -
diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index 1564a64..73896d8 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -14,6 +14,7 @@ en: config_successfully_copied: "Config has been copied successfully. Please restart %{brand} to use the new config" note_updating_success: "Note successfully updated." dryrun_is_passed: config test passed + no_diff: There is no difference in files. terms: &terms name: Name diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index b048fdf..c8da92b 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -14,6 +14,7 @@ ja: config_successfully_copied: "設定をコピーしました。反映させるには、 %{brand}を再起動してください。" note_updating_success: "メモを更新しました。" dryrun_is_passed: この設定でのdry-runが成功しました + no_diff: ファイル間の差異はありません。 terms: &terms name: アカウント名 diff --git a/spec/features/fluentd/setting/histories_spec.rb b/spec/features/fluentd/setting/histories_spec.rb index 4495a52..e0965da 100644 --- a/spec/features/fluentd/setting/histories_spec.rb +++ b/spec/features/fluentd/setting/histories_spec.rb @@ -26,7 +26,8 @@ describe "histories", stub: :daemon do end describe 'show' do - let(:last_backup_file) { Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first) } + let!(:last_backup_file) { Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order.first) } + let!(:new_file) { Fluentd::SettingArchive::BackupFile.new(daemon.agent.backup_files_in_new_order[1]) } before do visit "/daemon/setting/histories/#{last_backup_file.file_id}" @@ -37,11 +38,25 @@ describe "histories", stub: :daemon do page.should have_text(last_backup_file.content) end - it 'shows diff between current and target' do - page.should have_text("- type http") - page.should have_text("+ type forward") - page.should have_text("- port 8899") - page.should have_text("+ port 24224") + describe 'diff' do + context 'has diff' do + it 'shows diff between current and target' do + page.should have_text("- type http") + page.should have_text("+ type forward") + page.should have_text("- port 8899") + page.should have_text("+ port 24224") + end + end + + context 'has no diff' do + before do + visit "/daemon/setting/histories/#{new_file.file_id}" + end + + it 'shows no diff message' do + page.should have_text(I18n.t('messages.no_diff')) + end + end end it 'update config and redirect to setting#show' do diff --git a/spec/features/fluentd/setting/running_backup_spec.rb b/spec/features/fluentd/setting/running_backup_spec.rb index aae7e47..52a3f23 100644 --- a/spec/features/fluentd/setting/running_backup_spec.rb +++ b/spec/features/fluentd/setting/running_backup_spec.rb @@ -8,7 +8,7 @@ describe "running_backup", stub: :daemon do login_with exists_user end - context 'has running backup file' do + context 'has no running backup file' do before do visit '/daemon/setting/running_backup' end @@ -36,10 +36,25 @@ describe "running_backup", stub: :daemon do expect(page).to have_text(I18n.t("terms.reuse")) end - it 'has diff' do - expect(page).to have_text("- type http") - expect(page).to have_text("- port 8899") - expect(page).to have_text("+ Running backup file content") + describe 'diff' do + context 'has diff' do + it 'shows diff between current and running' do + expect(page).to have_text("- type http") + expect(page).to have_text("- port 8899") + expect(page).to have_text("+ Running backup file content") + end + end + + context 'has no diff' do + before do + daemon.agent.config_write backup_content + visit '/daemon/setting/running_backup' + end + + it 'shows no diff message' do + page.should have_text(I18n.t('messages.no_diff')) + end + end end it 'update config and redirect to setting#show' do