Change not to show source when

There is no difference between config files
This commit is contained in:
鳥井 雪 2015-02-04 16:52:35 +09:00
parent b8d4a42e7e
commit 726e910ff4
7 changed files with 75 additions and 26 deletions

View File

@ -177,3 +177,11 @@ label {
background-color: #dfd; background-color: #dfd;
} }
} }
.frame-corner-radius {
border: 1px solid #ddd;
padding:10px 10px;
border-radius: 3px;
margin: 10px 0px;
}

View File

@ -10,7 +10,10 @@ module SettingHistoryConcern
def show def show
current = @fluentd.agent.config current = @fluentd.agent.config
target = @backup_file.content 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 end
def reuse def reuse

View File

@ -1,15 +1,21 @@
<pre> <% if @changed %>
<% @sdiff.each do |diff| %> <pre>
<% case diff.action %> <% @sdiff.each do |diff| %>
<% when "=" %> <% case diff.action %>
<span class="stay"><%= diff.new_element %></span> <% when "=" %>
<% when "!" %> <span class="stay"><%= diff.new_element %></span>
<span class="deleted">- <%= diff.old_element %></span> <% when "!" %>
<span class="added">+ <%= diff.new_element %></span> <span class="deleted">- <%= diff.old_element %></span>
<% when "-" %> <span class="added">+ <%= diff.new_element %></span>
<span class="deleted">- <%= diff.old_element %></span> <% when "-" %>
<% when "+" %> <span class="deleted">- <%= diff.old_element %></span>
<span class="added">+ <%= diff.new_element %></span> <% when "+" %>
<span class="added">+ <%= diff.new_element %></span>
<% end %>
<% end %>
</pre>
<% else %>
<div class="frame-corner-radius">
<%= t('messages.no_diff') %>
</div>
<% end %> <% end %>
<% end %>
</pre>

View File

@ -14,6 +14,7 @@ en:
config_successfully_copied: "Config has been copied successfully. Please restart %{brand} to use the new config" config_successfully_copied: "Config has been copied successfully. Please restart %{brand} to use the new config"
note_updating_success: "Note successfully updated." note_updating_success: "Note successfully updated."
dryrun_is_passed: config test passed dryrun_is_passed: config test passed
no_diff: There is no difference in files.
terms: &terms terms: &terms
name: Name name: Name

View File

@ -14,6 +14,7 @@ ja:
config_successfully_copied: "設定をコピーしました。反映させるには、 %{brand}を再起動してください。" config_successfully_copied: "設定をコピーしました。反映させるには、 %{brand}を再起動してください。"
note_updating_success: "メモを更新しました。" note_updating_success: "メモを更新しました。"
dryrun_is_passed: この設定でのdry-runが成功しました dryrun_is_passed: この設定でのdry-runが成功しました
no_diff: ファイル間の差異はありません。
terms: &terms terms: &terms
name: アカウント名 name: アカウント名

View File

@ -26,7 +26,8 @@ describe "histories", stub: :daemon do
end end
describe 'show' do 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 before do
visit "/daemon/setting/histories/#{last_backup_file.file_id}" visit "/daemon/setting/histories/#{last_backup_file.file_id}"
@ -37,12 +38,26 @@ describe "histories", stub: :daemon do
page.should have_text(last_backup_file.content) page.should have_text(last_backup_file.content)
end end
describe 'diff' do
context 'has diff' do
it 'shows diff between current and target' do it 'shows diff between current and target' do
page.should have_text("- type http") page.should have_text("- type http")
page.should have_text("+ type forward") page.should have_text("+ type forward")
page.should have_text("- port 8899") page.should have_text("- port 8899")
page.should have_text("+ port 24224") page.should have_text("+ port 24224")
end 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 it 'update config and redirect to setting#show' do
click_link I18n.t("terms.reuse") click_link I18n.t("terms.reuse")

View File

@ -8,7 +8,7 @@ describe "running_backup", stub: :daemon do
login_with exists_user login_with exists_user
end end
context 'has running backup file' do context 'has no running backup file' do
before do before do
visit '/daemon/setting/running_backup' visit '/daemon/setting/running_backup'
end end
@ -36,11 +36,26 @@ describe "running_backup", stub: :daemon do
expect(page).to have_text(I18n.t("terms.reuse")) expect(page).to have_text(I18n.t("terms.reuse"))
end end
it 'has diff' do 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("- type http")
expect(page).to have_text("- port 8899") expect(page).to have_text("- port 8899")
expect(page).to have_text("+ Running backup file content") expect(page).to have_text("+ Running backup file content")
end 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 it 'update config and redirect to setting#show' do
click_link I18n.t("terms.reuse") click_link I18n.t("terms.reuse")