osaka 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ module CommonFlows
11
11
 
12
12
  pages = Osaka::Pages.new
13
13
  pages.open(pages_file)
14
+ pages.set_mail_merge_document(numbers_file)
14
15
  pages.mail_merge_to_pdf(output_file)
15
16
  pages.close(:dont_save)
16
17
  pages.quit(:dont_save)
data/lib/osaka/pages.rb CHANGED
@@ -1,5 +1,9 @@
1
1
 
2
2
  module Osaka
3
+
4
+ class PagesError < RuntimeError
5
+ end
6
+
3
7
  class PagesMailMergeDialog
4
8
  attr_accessor :control, :location
5
9
 
@@ -88,11 +92,11 @@ module Osaka
88
92
  open_dialog = do_and_wait_for_new_window {
89
93
  control.click(at.radio_button("Numbers Document:").radio_group(1).sheet(1))
90
94
  }
91
- dialog = create_dialog(TypicalOpenDialog, at.window(open_dialog))
92
- dialog.set_folder(File.dirname(filename))
93
- dialog.select_file(File.basename(filename))
94
- control.click(at.button("OK").sheet(1))
95
-
95
+ select_file_from_open_dialog(filename, at.window(open_dialog))
96
+ if (control.exists?(at.sheet(1).sheet(1)))
97
+ raise(PagesError, "Setting Mail Merge numbers file failed")
98
+ end
99
+ control.click(at.button("OK").sheet(1))
96
100
  end
97
101
 
98
102
  def mail_merge_field(field_name)
data/lib/osaka/preview.rb CHANGED
@@ -16,10 +16,8 @@ module Osaka
16
16
 
17
17
  def open(filename)
18
18
  control.click_menu_bar(at.menu_item("Open…"), "File").wait_until_exists(at.window("Open"))
19
- dialog = create_dialog(TypicalOpenDialog, at.window("Open"))
20
- dialog.set_folder(File.dirname(filename))
21
19
  new_window = do_and_wait_for_new_window {
22
- dialog.select_file(File.basename(filename))
20
+ select_file_from_open_dialog(filename, at.window("Open"))
23
21
  }
24
22
  control.set_current_window(new_window)
25
23
  end
@@ -191,5 +191,11 @@ module Osaka
191
191
  dialog_class.new(control.name, location + (location.has_top_level_element? ? "" : control.base_location))
192
192
  end
193
193
 
194
+ def select_file_from_open_dialog(filename, dialog_location)
195
+ dialog = create_dialog(TypicalOpenDialog, dialog_location)
196
+ dialog.set_folder(File.dirname(filename))
197
+ dialog.select_file(File.basename(filename))
198
+
199
+ end
194
200
  end
195
201
  end
data/lib/osaka/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Osaka
3
- VERSION = "0.4.4"
3
+ VERSION = "0.4.5"
4
4
  end
@@ -13,6 +13,7 @@ describe "Mail Merge to PDF common flow" do
13
13
  Osaka::Pages.should_receive(:new).and_return(mock_pages)
14
14
 
15
15
  mock_pages.should_receive(:open).with("/template/pages")
16
+ mock_pages.should_receive(:set_mail_merge_document).with("/template/numbers")
16
17
  mock_pages.should_receive(:mail_merge_to_pdf).with("/output/file.pdf")
17
18
 
18
19
  mock_pages.should_receive(:close).with(:dont_save)
data/spec/pages_spec.rb CHANGED
@@ -84,15 +84,26 @@ describe "Osaka::Pages" do
84
84
  subject.should_receive(:do_and_wait_for_new_window).and_yield.and_return("dialog")
85
85
  expect_click(at.radio_button("Numbers Document:").radio_group(1).sheet(1))
86
86
 
87
- dialog_mock = mock("Open Dialog")
88
- subject.should_receive(:create_dialog).with(Osaka::TypicalOpenDialog, at.window("dialog")).and_return(dialog_mock)
89
- dialog_mock.should_receive(:set_folder).with("/tmp")
90
- dialog_mock.should_receive(:select_file).with("filename")
87
+ subject.should_receive(:select_file_from_open_dialog).with("/tmp/filename", at.window("dialog"))
91
88
  expect_click(at.button("OK").sheet(1))
92
89
 
93
- subject.set_mail_merge_document("/tmp/filename")
90
+ expect_exists?(at.sheet(1).sheet(1)).and_return(false)
91
+ subject.set_mail_merge_document("/tmp/filename")
94
92
  end
95
93
 
94
+ it "Should be able to stop when an error happens due to mail merge. This is especially important since otherwise Pages goes nuts and crashes :)" do
95
+ subject.should_receive(:inspector).and_return(mock("Inspector").as_null_object)
96
+ expect_wait_until_exists(at.sheet(1))
97
+ subject.should_receive(:do_and_wait_for_new_window)
98
+ subject.should_receive(:select_file_from_open_dialog)
99
+
100
+ expect_exists?(at.sheet(1).sheet(1)).and_return(true)
101
+
102
+ expect {subject.set_mail_merge_document("/tmp/filename") }.to raise_error(Osaka::PagesError, "Setting Mail Merge numbers file failed")
103
+
104
+ end
105
+
106
+
96
107
  it "Should be able to insert a merge field" do
97
108
  expect_click_menu_bar(at.menu_item("Data").menu(1).menu_item("Merge Field"), "Insert")
98
109
  subject.mail_merge_field("Data")
data/spec/preview_spec.rb CHANGED
@@ -14,14 +14,11 @@ describe "Preview application for reading PDFs" do
14
14
  end
15
15
 
16
16
  it "Can open a PDF file via the menu instead of the AppleScript 'open' as that one is buggy" do
17
- open_dialog = mock("Open Dialog")
18
17
 
19
18
  expect_click_menu_bar(at.menu_item("Open…"), "File")
20
19
  expect_wait_until_exists(at.window("Open"))
21
20
  subject.stub(:do_and_wait_for_new_window).and_yield.and_return("window name")
22
- subject.should_receive(:create_dialog).with(Osaka::TypicalOpenDialog, at.window("Open")).and_return(open_dialog)
23
- open_dialog.should_receive(:set_folder).with("dir")
24
- open_dialog.should_receive(:select_file).with("filename")
21
+ subject.should_receive(:select_file_from_open_dialog).with("dir/filename", at.window("Open"))
25
22
  expect_set_current_window("window name")
26
23
 
27
24
  subject.open("dir/filename")
@@ -166,6 +166,15 @@ describe "Osaka::TypicalApplication" do
166
166
  subject.wait_for_save_dialog_and_save_file("/tmp/filename")
167
167
  end
168
168
 
169
+ it "Should be able to pick a file from an open dialog" do
170
+ dialog_mock = mock("Open Dialog")
171
+ subject.should_receive(:create_dialog).with(Osaka::TypicalOpenDialog, at.window("dialog")).and_return(dialog_mock)
172
+ dialog_mock.should_receive(:set_folder).with("/tmp")
173
+ dialog_mock.should_receive(:select_file).with("filename")
174
+
175
+ subject.select_file_from_open_dialog("/tmp/filename", at.window("dialog"))
176
+ end
177
+
169
178
 
170
179
  it "Should be able to duplicate and close the original document" do
171
180
  subject.stub_chain(:duplicate, :control).and_return(new_instance_control)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: osaka
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bas Vodde