Skip to content

Commit

Permalink
trim down I18n text for custom menu/prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Oct 23, 2018
1 parent 67f2a59 commit 738ba47
Showing 1 changed file with 39 additions and 62 deletions.
101 changes: 39 additions & 62 deletions spec/database_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@
end

# this is the complete implementation. the other 2 are paired down version of this
context "with localized file upload" do
it "displays custom ftp option with no prompts" do
context "with custom menu config" do
before do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
end

it "displays custom ftp option with no prompts" do
expect(I18n).to receive(:t).with("database_admin.prompts", :default=>{}).and_return({})
expect(subject).to receive(:ask_local_file_options).once
say ""
Expand All @@ -131,9 +134,7 @@
end

it "displays custom ftp option with other prompts" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :filename_text => "" })
expect_custom_prompts("example.com", :filename_text => "")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -149,9 +150,7 @@
end

it "displays custom ftp option with enabled blank" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => "" })
expect_custom_prompts("example.com", :enabled_for => "")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -167,9 +166,7 @@
end

it "displays custom ftp option with enabled string" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => "restore" })
expect_custom_prompts("example.com", :enabled_for => "restore")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -185,9 +182,7 @@
end

it "displays custom ftp option with enabled array" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => %w(restore backup) })
expect_custom_prompts("example.com", :enabled_for => %w(restore backup))
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -203,9 +198,7 @@
end

it "hides custom ftp option with other string prompts" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => "backup" })
expect_custom_prompts("example.com", :enabled_for => "backup")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -220,9 +213,7 @@
end

it "hides custom ftp option with other array prompts" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => %w(backup dump) })
expect_custom_prompts("example.com", :enabled_for => %w(backup dump))
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand Down Expand Up @@ -661,12 +652,7 @@

context "with custom prompts" do
before do
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).twice.and_return(
host.to_sym => {
:filename_text => "Target please",
:filename_validator => "^[0-9]+-.+$"
}
)
expect_custom_prompts(host, :filename_text => "Target please", :filename_validator => "^[0-9]+-.+$").twice

# if it doesn't ask again, it won't get the right task_params
say ["", "bad-2", target]
Expand Down Expand Up @@ -997,10 +983,13 @@ def confirm_and_execute
expect { subject.ask_file_location }.to raise_error signal_error
end

context "with localized file upload" do
it "displays custom ftp option with blank prompts" do
context "with custom menu config" do
before do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
end

it "displays custom ftp option with blank prompts" do
expect(I18n).to receive(:t).with("database_admin.prompts", :default=>{}).and_return({})
expect(subject).to receive(:ask_local_file_options).once
say ""
Expand All @@ -1017,9 +1006,7 @@ def confirm_and_execute
end

it "displays custom ftp option with enabled array" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => %w(restore backup) })
expect_custom_prompts("example.com", :enabled_for => %w(restore backup))
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -1034,10 +1021,8 @@ def confirm_and_execute
PROMPT
end

it "hids custom ftp option with disabled string" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => "dump" })
it "hides custom ftp option with disabled string" do
expect_custom_prompts("example.com", :enabled_for => "dump")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand Down Expand Up @@ -1486,12 +1471,7 @@ def confirm_and_execute

context "with custom prompts" do
before do
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).twice.and_return(
host.to_sym => {
:filename_text => "Target please",
:filename_validator => "^[0-9]+-.+$"
}
)
expect_custom_prompts(host, :filename_text => "Target please", :filename_validator => "^[0-9]+-.+$").twice

# if it doesn't ask again, it won't get the right task_params
say ["", "bad-2", target]
Expand Down Expand Up @@ -1520,13 +1500,11 @@ def confirm_and_execute
]
end
before do
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).at_least(:once).and_return(
host.to_sym => {
:filename_text => "Target please",
:filename_validator => "^[0-9]+-.+$",
:rake_options => { :skip_directory => true },
}
)
expect_custom_prompts(host,
:filename_text => "Target please",
:filename_validator => "^[0-9]+-.+$",
:rake_options => { :skip_directory => true },
).twice

# if it doesn't ask again, it won't get the right task_params
say ["", "bad-2", target]
Expand Down Expand Up @@ -1832,10 +1810,13 @@ def confirm_and_execute
expect { subject.ask_file_location }.to raise_error signal_error
end

context "with localized file upload" do
it "displays custom ftp option with blank prompts" do
context "with custom menu config" do
before do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
end

it "displays custom ftp option with blank prompts" do
expect(I18n).to receive(:t).with("database_admin.prompts", :default=>{}).and_return({})
expect(subject).to receive(:ask_local_file_options).once
say ""
Expand All @@ -1852,9 +1833,7 @@ def confirm_and_execute
end

it "displays custom ftp option with enabled array" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => %w(dump backup) })
expect_custom_prompts("example.com", :enabled_for => %w(dump backup))
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand All @@ -1870,9 +1849,7 @@ def confirm_and_execute
end

it "hides custom ftp option with other string prompts" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).and_return(:"example.com" => { :enabled_for => "backup" })
expect_custom_prompts("example.com", :enabled_for => "backup")
expect(subject).to receive(:ask_local_file_options).once
say ""
subject.ask_file_location
Expand Down Expand Up @@ -2189,12 +2166,7 @@ def confirm_and_execute

context "with custom prompts" do
before do
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).twice.and_return(
host.to_sym => {
:filename_text => "Target please",
:filename_validator => "^[0-9]+-.+$"
}
)
expect_custom_prompts(host, :filename_text => "Target please", :filename_validator => "^[0-9]+-.+$").twice

# if it doesn't ask again, it won't get the right task_params
say ["", "bad-2", target]
Expand Down Expand Up @@ -2476,4 +2448,9 @@ def confirm_and_execute
expect(subject).not_to be_local_backup
end
end

def expect_custom_prompts(hostname, values)
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {})
.and_return(hostname.to_sym => values)
end
end

0 comments on commit 738ba47

Please sign in to comment.