Permalink
Browse files

A couple of specs for compile and runtime errors

  • Loading branch information...
1 parent 1cd5652 commit 297b780d51b642052195fc9b6e78ab94c26af7d8 @msaraiva msaraiva committed Oct 11, 2012
View
@@ -4,3 +4,4 @@ Gemfile.lock
pkg/*
.DS_Store
.project
+*.jasper
@@ -1,24 +1,69 @@
require 'spec_helper'
describe PeopleController do
- describe "GET listagem" do
+
+ describe "GET index" do
before do
- Person.stub(:all).and_return([Person.new(:name=>'jonh', :email=>'lennon@beatles.com'), Person.new(:name=>'paul', :email=>'paul@beatles.com')])
+ Person.stub(:all).and_return([
+ Person.new(:name=>'john' , :email=>'lennon@beatles.com'),
+ Person.new(:name=>'george', :email=>'harrison@beatles.com')
+ ])
end
- it "be success" do
+ it "should respond success" do
+ get :index, :format => :pdf
+
response.should be_success
end
it "should not contain nulls" do
get :index, :format => :pdf
+
response.should_not contain("null")
end
- it "should contain emails" do
+ it "should show all fields in the report" do
get :index, :format => :pdf
+
+ response.should contain("john")
response.should contain("lennon@beatles.com")
- response.should contain("paul@beatles.com")
+ response.should contain("george")
+ response.should contain("harrison@beatles.com")
+ end
+
+ it "should clip the text if it's larger than the Text Field" do
+ Person.stub(:all).and_return([
+ Person.new(:name=>'jonh' , :email=>'a_very_long_text_that_is_larger_than_the_text_field_in_the_report')
+ ])
+
+ get :index, :format => :pdf
+
+ response.should_not contain("a_very_long_text_that_is_larger_than_the_text_field_in_the_report")
+ response.should contain("a_very_long_text_that_is_larger_than_the_text_field_in_the_")
+ end
+
+ it "should show the parameters defined in the controller" do
+ get :index, :format => :pdf
+
+ response.should contain("I'm a parameter. I was defined in the controller")
end
+
end
+
+ describe "GET compile_time_error_report" do
+
+ it "should raise a RuntimeError if the report's design is not valid" do
+ expect { get :compile_time_error_report, :format => :pdf }.to raise_error(RuntimeError, /Report design not valid/)
+ end
+
+ end
+
+ describe "GET runtime_error_report" do
+
+ it "should raise a RuntimeError if the report could not be filled due to a runtime error" do
+ expect { get :runtime_error_report, :format => :pdf }.to raise_error(RuntimeError)
+ end
+
+ end
+
end
@@ -3,7 +3,18 @@ class PeopleController < ActionController::Base
def index
@people = Person.all
+
+ @parameter_defined_in_the_controller = "I'm a parameter. I was defined in the controller"
+
respond_with @people
end
+ def compile_time_error_report
+ respond_with []
+ end
+
+ def runtime_error_report
+ respond_with []
+ end
+
end
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="index" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="311ea5a2-cc66-43bf-9af3-b2e0a552b1de">
+ <property name="ireport.zoom" value="1.0"/>
+ <property name="ireport.x" value="0"/>
+ <property name="ireport.y" value="0"/>
+ <style name="Title" forecolor="#FFFFFF" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
+ <style name="SubTitle" forecolor="#666666" fontName="Arial" fontSize="18"/>
+ <style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
+ <style name="Detail" fontName="Arial" fontSize="12"/>
+ <parameter name="parameter_defined_in_the_controller" class="java.lang.String"/>
+ <queryString language="xPath">
+ <![CDATA[/people/person]]>
+ </queryString>
+ <field name="name" class="java.lang.String">
+ <fieldDescription><![CDATA[name]]></fieldDescription>
+ </field>
+ <field name="email" class="java.lang.String">
+ <fieldDescription><![CDATA[email]]></fieldDescription>
+ </field>
+ <background>
+ <band splitType="Stretch"/>
+ </background>
+ <title>
+ <band height="70" splitType="Stretch">
+ <image>
+ <reportElement uuid="0b15b501-e65d-4f8b-b890-759a6d279efe" x="-20" y="0" width="595" height="64"/>
+ <imageExpression><![CDATA["wood.jpg"]]></imageExpression>
+ </image>
+ <staticText>
+ <reportElement uuid="dfeee47e-d32e-4525-a708-7cc3d6ec3f91" style="Title" x="0" y="5" width="263" height="33"/>
+ <textElement verticalAlignment="Middle"/>
+ <text><![CDATA[jasper-rails]]></text>
+ </staticText>
+ <textField>
+ <reportElement uuid="91699025-171b-40b4-ae45-eb9cdca69b2b" x="97" y="38" width="358" height="20" forecolor="#FFFFFF"/>
+ <textElement>
+ <font size="15"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$P{undefined_parameter}]]></textFieldExpression>
+ </textField>
+ </band>
+ </title>
+ <pageHeader>
+ <band splitType="Stretch"/>
+ </pageHeader>
+ <columnHeader>
+ <band height="36" splitType="Stretch">
+ <line>
+ <reportElement uuid="6a63817d-d338-4966-9432-96e7baffc7f8" positionType="FixRelativeToBottom" x="0" y="35" width="555" height="1"/>
+ <graphicElement>
+ <pen lineWidth="0.5" lineColor="#999999"/>
+ </graphicElement>
+ </line>
+ <staticText>
+ <reportElement uuid="89d037e3-230c-4845-b0aa-a43920c60dc2" x="48" y="15" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[name]]></text>
+ </staticText>
+ <staticText>
+ <reportElement uuid="6920786b-3719-4243-bee2-9e4073274cb1" x="245" y="15" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[email]]></text>
+ </staticText>
+ </band>
+ </columnHeader>
+ <detail>
+ <band height="21" splitType="Stretch">
+ <textField>
+ <reportElement uuid="63d9b6a9-caa5-40d8-8bb0-41822dd43364" x="48" y="0" width="185" height="20"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
+ </textField>
+ <textField>
+ <reportElement uuid="83b41533-c6ed-4de6-8c48-5545c9c78e43" x="245" y="0" width="290" height="20"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
+ </textField>
+ </band>
+ </detail>
+ <columnFooter>
+ <band height="45" splitType="Stretch">
+ <line>
+ <reportElement uuid="9642b713-530f-4d6e-a4dd-b6e7b4d07e2b" positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
+ <graphicElement>
+ <pen lineWidth="0.5" lineColor="#999999"/>
+ </graphicElement>
+ </line>
+ </band>
+ </columnFooter>
+ <pageFooter>
+ <band height="20" splitType="Stretch">
+ <textField>
+ <reportElement uuid="06b23f1b-7ac0-4c70-bb2e-2aeb039f67a3" style="Column header" x="433" y="0" width="80" height="20"/>
+ <textElement textAlignment="Right">
+ <font size="10" isBold="false"/>
+ </textElement>
+ <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
+ </textField>
+ <textField evaluationTime="Report">
+ <reportElement uuid="b8b7868e-fe9c-4e1b-8a24-75b97450ef73" style="Column header" x="513" y="0" width="40" height="20"/>
+ <textElement>
+ <font size="10" isBold="false"/>
+ </textElement>
+ <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
+ </textField>
+ <textField pattern="EEEEE dd MMMMM yyyy">
+ <reportElement uuid="f924a532-c0df-4366-baad-4126ffb1462f" style="Column header" x="0" y="0" width="197" height="20"/>
+ <textElement>
+ <font size="10" isBold="false"/>
+ </textElement>
+ <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
+ </textField>
+ </band>
+ </pageFooter>
+ <summary>
+ <band splitType="Stretch"/>
+ </summary>
+</jasperReport>
Binary file not shown.
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="index" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="index" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="311ea5a2-cc66-43bf-9af3-b2e0a552b1de">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="Title" forecolor="#FFFFFF" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
<style name="SubTitle" forecolor="#666666" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Arial" fontSize="12"/>
+ <parameter name="parameter_defined_in_the_controller" class="java.lang.String"/>
<queryString language="xPath">
<![CDATA[/people/person]]>
</queryString>
@@ -22,19 +23,21 @@
<title>
<band height="70" splitType="Stretch">
<image>
- <reportElement x="-20" y="0" width="595" height="64"/>
+ <reportElement uuid="0b15b501-e65d-4f8b-b890-759a6d279efe" x="-20" y="0" width="595" height="64"/>
<imageExpression><![CDATA["wood.jpg"]]></imageExpression>
</image>
<staticText>
- <reportElement style="Title" x="0" y="5" width="263" height="33"/>
+ <reportElement uuid="dfeee47e-d32e-4525-a708-7cc3d6ec3f91" style="Title" x="0" y="5" width="263" height="33"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[jasper-rails]]></text>
</staticText>
- <staticText>
- <reportElement style="SubTitle" x="0" y="38" width="200" height="22" forecolor="#FFFFFF"/>
- <textElement textAlignment="Right"/>
- <text><![CDATA[v 0.1.0]]></text>
- </staticText>
+ <textField>
+ <reportElement uuid="91699025-171b-40b4-ae45-eb9cdca69b2b" x="97" y="38" width="358" height="20" forecolor="#FFFFFF"/>
+ <textElement>
+ <font size="15"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$P{parameter_defined_in_the_controller}]]></textFieldExpression>
+ </textField>
</band>
</title>
<pageHeader>
@@ -43,18 +46,18 @@
<columnHeader>
<band height="36" splitType="Stretch">
<line>
- <reportElement positionType="FixRelativeToBottom" x="0" y="35" width="555" height="1"/>
+ <reportElement uuid="6a63817d-d338-4966-9432-96e7baffc7f8" positionType="FixRelativeToBottom" x="0" y="35" width="555" height="1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
<staticText>
- <reportElement x="48" y="15" width="100" height="20"/>
+ <reportElement uuid="89d037e3-230c-4845-b0aa-a43920c60dc2" x="48" y="15" width="100" height="20"/>
<textElement/>
<text><![CDATA[name]]></text>
</staticText>
<staticText>
- <reportElement x="245" y="15" width="100" height="20"/>
+ <reportElement uuid="6920786b-3719-4243-bee2-9e4073274cb1" x="245" y="15" width="100" height="20"/>
<textElement/>
<text><![CDATA[email]]></text>
</staticText>
@@ -63,12 +66,12 @@
<detail>
<band height="21" splitType="Stretch">
<textField>
- <reportElement x="48" y="0" width="185" height="20"/>
+ <reportElement uuid="63d9b6a9-caa5-40d8-8bb0-41822dd43364" x="48" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
- <reportElement x="245" y="0" width="290" height="20"/>
+ <reportElement uuid="83b41533-c6ed-4de6-8c48-5545c9c78e43" x="245" y="0" width="290" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
@@ -77,7 +80,7 @@
<columnFooter>
<band height="45" splitType="Stretch">
<line>
- <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
+ <reportElement uuid="9642b713-530f-4d6e-a4dd-b6e7b4d07e2b" positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
@@ -87,21 +90,21 @@
<pageFooter>
<band height="20" splitType="Stretch">
<textField>
- <reportElement style="Column header" x="433" y="0" width="80" height="20"/>
+ <reportElement uuid="06b23f1b-7ac0-4c70-bb2e-2aeb039f67a3" style="Column header" x="433" y="0" width="80" height="20"/>
<textElement textAlignment="Right">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
- <reportElement style="Column header" x="513" y="0" width="40" height="20"/>
+ <reportElement uuid="b8b7868e-fe9c-4e1b-8a24-75b97450ef73" style="Column header" x="513" y="0" width="40" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
- <reportElement style="Column header" x="0" y="0" width="197" height="20"/>
+ <reportElement uuid="f924a532-c0df-4366-baad-4126ffb1462f" style="Column header" x="0" y="0" width="197" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
Oops, something went wrong.

0 comments on commit 297b780

Please sign in to comment.