"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/controller_test.rb" between
ruport-1.7.1.tar.gz and ruport-1.8.0.tar.gz

About: Ruport (Ruby Reports) is a simple, extensible reporting system built for Rubyists. It provides tools for data acquisition, database interaction, formatting, and parsing/munging.

controller_test.rb  (ruport-1.7.1):controller_test.rb  (ruport-1.8.0)
skipping to change at line 107 skipping to change at line 107
def teardown def teardown
Ruport::Formatter::Template.instance_variable_set(:@templates, nil) Ruport::Formatter::Template.instance_variable_set(:@templates, nil)
end end
def test_trivial def test_trivial
actual = OldSchoolController.render(:text) actual = OldSchoolController.render(:text)
assert_equal "header\nbody\nfooter\n", actual assert_equal "header\nbody\nfooter\n", actual
end end
context "when running a formatter with custom a finalize method" do context "when running a formatter with custom a finalize method" do
def specify_finalize_method_should_be_called should "specify_finalize_method_should_be_called" do
assert_equal "I has been finalized", assert_equal "I has been finalized",
VanillaController.render_with_finalize VanillaController.render_with_finalize
end end
end end
context "when using templates" do context "when using templates" do
def specify_apply_template_should_be_called should "specify_apply_template_should_be_called" do
Ruport::Formatter::Template.create(:stub) Ruport::Formatter::Template.create(:stub)
Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r| Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r|
r.formatter.expects(:apply_template) r.formatter.expects(:apply_template)
end end
end end
def specify_undefined_template_should_throw_sensible_error should "specify_undefined_template_should_throw_sensible_error" do
assert_raises(Ruport::Formatter::TemplateNotDefined) do assert_raises(Ruport::Formatter::TemplateNotDefined) do
Ruport.Table(%w[a b c]).to_csv(:template => :sub) Ruport.Table(%w[a b c]).to_csv(:template => :sub)
end end
end end
end end
context "when using default templates" do context "when using default templates" do
def specify_default_template_should_be_called should "specify_default_template_should_be_called" do
Ruport::Formatter::Template.create(:default) Ruport::Formatter::Template.create(:default)
Ruport.Table(%w[a b c]).to_csv do |r| Ruport.Table(%w[a b c]).to_csv do |r|
r.formatter.expects(:apply_template) r.formatter.expects(:apply_template)
assert r.formatter.template == Ruport::Formatter::Template[:default] assert r.formatter.template == Ruport::Formatter::Template[:default]
end end
end end
def specify_specific_should_override_default should "specify_specific_should_override_default" do
Ruport::Formatter::Template.create(:default) Ruport::Formatter::Template.create(:default)
Ruport::Formatter::Template.create(:stub) Ruport::Formatter::Template.create(:stub)
Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r| Ruport.Table(%w[a b c]).to_csv(:template => :stub) do |r|
r.formatter.expects(:apply_template) r.formatter.expects(:apply_template)
assert r.formatter.template == Ruport::Formatter::Template[:stub] assert r.formatter.template == Ruport::Formatter::Template[:stub]
end end
end end
def specify_should_be_able_to_disable_templates should "specify_should_be_able_to_disable_templates" do
Ruport::Formatter::Template.create(:default) Ruport::Formatter::Template.create(:default)
Ruport.Table(%w[a b c]).to_csv(:template => false) do |r| Ruport.Table(%w[a b c]).to_csv(:template => false) do |r|
r.formatter.expects(:apply_template).never r.formatter.expects(:apply_template).never
end end
end end
end end
def test_using_io def test_using_io
require "stringio" require "stringio"
out = StringIO.new out = StringIO.new
a = OldSchoolController.render(:text) { |r| r.io = out } OldSchoolController.render(:text) { |r| r.io = out }
out.rewind out.rewind
assert_equal "header\nbody\nfooter\n", out.read assert_equal "header\nbody\nfooter\n", out.read
assert_equal "", out.read assert_equal "", out.read
end end
def test_using_file def test_using_file
f = [] f = []
File.expects(:open).yields(f) File.expects(:open).yields(f)
a = OldSchoolController.render(:text, :file => "foo.text") OldSchoolController.render(:text, :file => "foo.text")
assert_equal "header\nbody\nfooter\n", f[0] assert_equal "header\nbody\nfooter\n", f[0]
f = [] f = []
File.expects(:open).with("blah","wb").yields(f) File.expects(:open).with("blah","wb").yields(f)
VanillaController.render(:bin, :file => "blah") VanillaController.render(:bin, :file => "blah")
end end
def test_using_file_via_rendering_tools def test_using_file_via_rendering_tools
f = [] f = []
File.expects(:open).yields(f) File.expects(:open).yields(f)
skipping to change at line 302 skipping to change at line 302
stage :header stage :header
stage :body stage :body
stage :footer stage :footer
finalize :document finalize :document
def setup def setup
options.apple = true options.apple = true
end end
end end
def test_hash_options_setters def test_hash_options_setters
a = ControllerWithManyHooks.render(:text, :subtitle => "foo", ControllerWithManyHooks.render(:text, :subtitle => "foo", :subsubtitle => "b
:subsubtitle => "bar") { |r| ar") do |r|
assert_equal "foo", r.options.subtitle assert_equal "foo", r.options.subtitle
assert_equal "bar", r.options.subsubtitle assert_equal "bar", r.options.subsubtitle
} end
end end
def test_data_accessors def test_data_accessors
a = ControllerWithManyHooks.render(:text, :data => [1,2,4]) { |r| ControllerWithManyHooks.render(:text, :data => [1,2,4]) do |r|
assert_equal [1,2,4], r.data assert_equal [1,2,4], r.data
} end
b = ControllerWithManyHooks.render_text(%w[a b c]) { |r| ControllerWithManyHooks.render_text(%w[a b c]) do |r|
assert_equal %w[a b c], r.data assert_equal %w[a b c], r.data
} end
c = ControllerWithManyHooks.render_text(%w[a b f],:snapper => :red) { |r| ControllerWithManyHooks.render_text(%w[a b f],:snapper => :red) do |r|
assert_equal %w[a b f], r.data assert_equal %w[a b f], r.data
assert_equal :red, r.options.snapper assert_equal :red, r.options.snapper
} end
end end
def test_formatter_data_dup def test_formatter_data_dup
source = "some text" source = "some text"
result = ControllerWithManyHooks.render(:destructive, :data => source) result = ControllerWithManyHooks.render(:destructive, :data => source)
assert_equal("You sent some text", result) assert_equal("You sent some text", result)
assert_equal("some text", source) assert_equal("some text", source)
end end
def test_stage_helper def test_stage_helper
skipping to change at line 681 skipping to change at line 679
rend = mock("renderer") rend = mock("renderer")
rend.expects(:data=).with(a) rend.expects(:data=).with(a)
Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend) Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
a.as(:csv) a.as(:csv)
end end
class DummyObject2 class DummyObject2
include Ruport::Controller::Hooks include Ruport::Controller::Hooks
renders_as_table renders_as_table
def renderable_data(format) def renderable_data(_format)
1 1
end end
end end
def test_should_return_results_of_renderable_data def test_should_return_results_of_renderable_data
a = DummyObject2.new a = DummyObject2.new
rend = mock("renderer") rend = mock("renderer")
rend.expects(:data=).with(1) rend.expects(:data=).with(1)
Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend) Ruport::Controller::Table.expects(:render).with(:csv,{}).yields(rend)
a.as(:csv) a.as(:csv)
 End of changes. 15 change blocks. 
23 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)