Permalink
Browse files

Adding some minimal RSpec tests

  • Loading branch information...
1 parent 55c8342 commit 1cd565278506e4bb46c5163394b051cbfd8dc958 @msaraiva msaraiva committed Oct 11, 2012
View
@@ -0,0 +1,7 @@
+require 'rubygems'
+require 'bundler'
+
+Bundler.require :default, :development
+
+Combustion.initialize!
+run Combustion::Application
@@ -17,4 +17,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency('rjb', '>= 1.4.0')
+ s.add_development_dependency 'combustion', '~> 0.3.2'
+ s.add_development_dependency "rspec-rails"
+ s.add_development_dependency "jasper-rails-rspec"
end
View
@@ -23,6 +23,7 @@
require "jasper-rails/version"
require "rails"
require "rjb"
+require "action_controller/metal/responder"
if Mime::Type.lookup_by_extension("pdf").nil?
Mime::Type.register "application/pdf", :pdf
@@ -104,7 +105,7 @@ def self.render_pdf(jasper_file, datasource, parameters, options)
class ActionController::Responder
def to_pdf
- jasper_file = "app/views/#{controller.controller_path}/#{controller.action_name}.jasper"
+ jasper_file = "#{Rails.root.to_s}/app/views/#{controller.controller_path}/#{controller.action_name}.jasper"
params = {}
controller.instance_variables.each do |v|
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe PeopleController do
+ describe "GET listagem" do
+ before do
+ Person.stub(:all).and_return([Person.new(:name=>'jonh', :email=>'lennon@beatles.com'), Person.new(:name=>'paul', :email=>'paul@beatles.com')])
+ end
+
+ it "be success" do
+ 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
+ get :index, :format => :pdf
+ response.should contain("lennon@beatles.com")
+ response.should contain("paul@beatles.com")
+ end
+ end
+end
@@ -0,0 +1,9 @@
+class PeopleController < ActionController::Base
+ respond_to :xml, :pdf
+
+ def index
+ @people = Person.all
+ respond_with @people
+ end
+
+end
@@ -0,0 +1,16 @@
+class Person
+ extend ActiveModel::Naming
+ include ActiveModel::Serializers::Xml
+
+ attr_accessor :name, :email
+
+ def initialize(hash)
+ hash.each do |key, value|
+ instance_variable_set("@#{key}", value)
+ end
+ end
+
+ def attributes
+ instance_values
+ end
+end
Binary file not shown.
@@ -0,0 +1,115 @@
+<?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">
+ <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"/>
+ <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 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"/>
+ <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>
+ </band>
+ </title>
+ <pageHeader>
+ <band splitType="Stretch"/>
+ </pageHeader>
+ <columnHeader>
+ <band height="36" splitType="Stretch">
+ <line>
+ <reportElement 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"/>
+ <textElement/>
+ <text><![CDATA[name]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="245" y="15" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[email]]></text>
+ </staticText>
+ </band>
+ </columnHeader>
+ <detail>
+ <band height="21" splitType="Stretch">
+ <textField>
+ <reportElement 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"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
+ </textField>
+ </band>
+ </detail>
+ <columnFooter>
+ <band height="45" splitType="Stretch">
+ <line>
+ <reportElement 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 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"/>
+ <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"/>
+ <textElement>
+ <font size="10" isBold="false"/>
+ </textElement>
+ <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
+ </textField>
+ </band>
+ </pageFooter>
+ <summary>
+ <band splitType="Stretch"/>
+ </summary>
+</jasperReport>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ resources :people
+end
@@ -0,0 +1 @@
+*.log
View
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'bundler'
+
+Bundler.require :default, :development
+
+Combustion.initialize! :action_controller
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+end

0 comments on commit 1cd5652

Please sign in to comment.