This repository has been archived by the owner on Aug 14, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for generate pdf private methods
- Loading branch information
Showing
8 changed files
with
111 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
#!/usr/bin/env ruby | |||
# encoding: UTF-8 | |||
|
|||
require 'test_helper' | |||
|
|||
class Foo | |||
include Princess::GeneratePdf | |||
|
|||
def params | |||
@params ||= Hash.new | |||
end | |||
end | |||
|
|||
class GeneratePdfTest < ActiveSupport::TestCase | |||
|
|||
# append_suffix | |||
test "should append suffix" do | |||
instance = Foo.new | |||
|
|||
assert_equal 'foo.bar', instance.send(:append_suffix, 'foo', :bar) | |||
end | |||
|
|||
test "should not append when suffix is already present" do | |||
instance = Foo.new | |||
|
|||
assert_equal 'foo.bar', instance.send(:append_suffix, 'foo.bar', :bar) | |||
end | |||
|
|||
|
|||
# princess_default_stylesheet | |||
test "should return application pdf stylesheet" do | |||
instance = Foo.new | |||
instance.params[:controller] = 'does_not_exist' | |||
|
|||
assert_equal 'application_default_pdf', instance.send(:princess_default_stylesheet) | |||
end | |||
|
|||
test "should return controller specific pdf stylesheet" do | |||
instance = Foo.new | |||
instance.params[:controller] = 'reports' | |||
|
|||
assert_equal 'reports_default_pdf', instance.send(:princess_default_stylesheet) | |||
end | |||
|
|||
|
|||
# princess_default_filename | |||
test "should return princess_default_filename" do | |||
instance = Foo.new | |||
instance.params[:controller] = 'foo' | |||
instance.params[:action] = 'bar' | |||
|
|||
assert_equal 'foo_bar.pdf', instance.send(:princess_default_filename) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
#Controller who's views are all in the .html.erb format | |||
class ErbArticlesController < ApplicationController | |||
|
|||
def show | |||
@article = Article.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
format.html | |||
format.pdf { render :pdf => true } | |||
end | |||
end | |||
|
|||
def custom_one | |||
@article = Article.find(params[:id]) | |||
respond_to do |format| | |||
format.html | |||
format.pdf { render :pdf => 'alternate_custom_one', :filename => "custom_one.pdf" } | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
class ReportsController < ApplicationController | |||
|
|||
REPMAPS = { | |||
'address_labels_avery_5160' => { | |||
:template => '/princess/avery_5160', | |||
:partial => 'address_label', | |||
:filename => 'address_labels', | |||
:stylesheet => 'address_labels', | |||
:layout => false | |||
}, | |||
'nametags_avery_5390' => { | |||
:template => '/princess/avery_5390', | |||
:partial => 'nametag', | |||
:filename => 'nametags', | |||
:stylesheet => 'nametags', | |||
:layout => false | |||
} | |||
} | |||
|
|||
def create | |||
map = REPMAPS[params[:report][:format]] | |||
|
|||
respond_to do |format| | |||
format.pdf { render :pdf => map.merge(:collection => %w(one two three four)) } | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
/* USED FOR TESTING */ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters