test/unit/report/test_base.rb in thinreports-0.9.1 vs test/unit/report/test_base.rb in thinreports-0.10.0

- old
+ new

@@ -1,6 +1,6 @@ -# coding: utf-8 +# frozen_string_literal: true require 'test_helper' class Thinreports::Report::TestBase < Minitest::Test include Thinreports::TestHelper @@ -116,21 +116,24 @@ @report.use_layout(@layout_file.path, id: :foo) assert_equal @report.layout(:foo).filename, @layout_file.path end - def test_generate_with_filename - report = Report::Base.new layout: @layout_file.path + def test_generate + report = Report::Base.new(layout: @layout_file.path) - report.generate :pdf, filename: temp_path.join('result1.pdf') - report.generate filename: temp_path.join('result2.pdf') + generator = mock('generator') + generator.expects(:generate).with('result.pdf') - assert File.exist?(temp_path.join('result1.pdf')) - assert File.exist?(temp_path.join('result2.pdf')) + Thinreports::Generator::PDF.expects(:new) + .with(report, { security: { owner_password: 'pass' }}) + .returns(generator) - assert_equal File.read(temp_path.join('result1.pdf')), - File.read(temp_path.join('result2.pdf')) + report.generate( + filename: 'result.pdf', + security: { owner_password: 'pass' } + ) end def test_page_should_return_the_current_page @report.use_layout(@layout_file.path) @report.start_new_page @@ -200,63 +203,46 @@ assert_raises ArgumentError do Report::Base.create end end - def test_Base_generate_with_filename - Report::Base.generate(:pdf, report: { layout: @layout_file.path }, - generator: { filename: temp_path.join('result1.pdf') }) {} - Report::Base.generate(report: { layout: @layout_file.path }, - generator: { filename: temp_path.join('result2.pdf') }) {} - - assert_equal temp_path.join('result1.pdf').read, - temp_path.join('result2.pdf').read - end - def test_Base_generate_should_raise_when_no_block_given assert_raises ArgumentError do Report::Base.generate(:pdf) end end - def test_Base_extract_options_should_return_as_report_option_the_value_which_has_report_in_a_key - report, _generator = Report::Base.send(:extract_options!, [{report: {layout: 'hoge.tlf'}}]) - assert_equal report[:layout], 'hoge.tlf' - end + def test_Base_generate_with_deprecated_arguments + Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report) + @report.expects(:generate).with( + filename: 'result.pdf', + security: { owner_password: 'pass' } + ) - def test_Base_extract_options_should_operate_an_argument_destructively - args = [:pdf, 'output.pdf', {report: {layout: 'foo.tlf'}}] - Report::Base.send(:extract_options!, args) - assert_equal args, [:pdf, 'output.pdf'] + Report::Base.generate( + report: { layout: '/path/to/layout.tlf' }, + generator: { + filename: 'result.pdf', + security: { owner_password: 'pass' } + } + ) { |_| } end - def test_Base_extract_options_should_include_the_layout_key_in_the_report_option - report, _generator = Report::Base.send(:extract_options!, [{layout: 'hoge.tlf'}]) - assert_equal report[:layout], 'hoge.tlf' - end + def test_Base_generate_argument_priority + Report::Base.expects(:create).with(layout: '/path/to/layout.tlf').returns(@report) + @report.expects(:generate).with( + filename: 'result.pdf', + security: { owner_password: 'pass' } + ) - def test_Base_extract_options_should_give_priority_to_the_value_of_the_layout_key_over_in_the_report_option - report, _generator = Report::Base.send(:extract_options!, - [{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf'}]) - assert_equal report[:layout], 'hoge.tlf' - end - - def test_Base_extract_options_should_return_as_generator_option_the_value_which_has_generator_in_a_key - _report, generator = Report::Base.send(:extract_options!, - [{generator: {option: 'value'}}]) - assert_equal generator[:option], 'value' - end - - def test_Base_extract_options_should_give_priority_to_the_value_of_other_keys_over_in_the_generator_option - _report, generator = Report::Base.send(:extract_options!, - [{generator: {option: 'value1'}, option: 'value2'}]) - assert_equal generator[:option], 'value2' - end - - def test_Base_extract_options_should_return_all_the_values_except_the_report_option_as_a_generator_option - _report, generator = Report::Base.send(:extract_options!, - [{report: {layout: 'foo.tlf'}, layout: 'hoge.tlf', - generator_opt1: 'value1', generator_opt2: 'value2'}]) - assert_equal generator.values_at(:generator_opt1, :generator_opt2), - ['value1', 'value2'] + Report::Base.generate( + layout: '/path/to/layout.tlf', + filename: 'result.pdf', + security: { owner_password: 'pass' }, + report: { layout: '/path/to/deprecated.tlf' }, + generator: { + filename: 'deprecated.pdf', + security: { owner_password: 'deprecated' } + } + ) { |_| } end end