Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method that allows the generation of report without writing to a file #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
test/dummy/config/jasperserver.yml
.ruby-version
7 changes: 4 additions & 3 deletions lib/jasperserver-rails/jasperserver-dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(&block)
login
end

def run_report(filename, &block)
def generate_report(&block)
instance_eval(&block) if block_given?
login
# Run report
Expand All @@ -37,11 +37,12 @@ def run_report(filename, &block)
).to_s,
{ cookies: @cookie }
)
end

# Write file
def run_report(filename, &block)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. This is the reason I reverted ffe38af. I wanted a separate method.

FileUtils.mkdir_p(File.expand_path(filename).split('/')[0..-2].join('/'))
f = File.new(filename, 'wb')
f.write(report_data.body)
f.write(generate_report(&block).body)
f.close
end

Expand Down
12 changes: 12 additions & 0 deletions test/jasperserver-rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ class JasperserverRailsTest < ActiveSupport::TestCase
File.exist? report_file
end

test 'report data is returned when simply generating the report' do
report_file = 'test/dummy/tmp/reports/test3.pdf'
VCR.use_cassette 'test3' do
report = JasperserverRails::Jasperserver.new.generate_report do
format 'pdf'
report 'reports/samples/Department'
params({ Value1: 'Value1' })
end
assert report
end
end

test 'stays logged in when running multiple reports' do
report_file = 'test/dummy/tmp/reports/test4.pdf'
VCR.use_cassette 'test4' do
Expand Down