Skip to content

Instantly share code, notes, and snippets.

String calculateStatus () {
// TODO Should we look at using a State pattern here? -Mark 11/10/09
def result = null
if (this.isCancelled()) {
return 'CANCELLED'
}
package models
import javax.persistence.*
import lib.ConversionUtils as CU
import lib.BigDecimalUtils as BDU
@Entity
@DiscriminatorValue("PO")
class PoLotJpaImpl extends LotJpaImpl {
void testCalculateDestinationTransportOrderDateOfArrivalScheduledShouldReturnTheTODateOfArrivalWhenThereIsATO () {
def lot = mockLot()
def to = new TransportOrderJpaImpl ()
def now = new Date ()
to.dateOfArrivalScheduled = now
lot.activeDestinationTransportOrders.returns([ to ])
lot.activeDestinationTransportOrders.returns([ to ])
play {
assertEquals(now, lot.calculateDestinationTransportOrderDateOfArrivalScheduled())
}
def result = this.invoiceLineItems.collect { it.quantityNet }.inject(0.0G) { sum, ili ->
sum + ili
}
This code throws:
java.lang.ClassCastException: java.lang.Integer cannot be cast to groovy.lang.Closure
at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:42)
at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:77)
at $Proxy1.getQuantityNet(Unknown Source)
class Member < ActiveRecord::Base
class << self
def new (attributes = nil, &block)
if self == Member
klass = Object.const_get("#{(ENV['MORI_ENV'] ? ENV['MORI_ENV'] : "").camelize}Member".to_sym)
if klass != Member
return klass.new(attributes, &block)
end
end
class Foo
# This way of calling define_method works.
define_method(:bar) do
puts self
end
# This fails saying define_method is a private method.
# Why, when self is obviously the object receiving the define_method message...?
self.define_method(:foo) do
puts self
end
class Post < ActiveRecord::Base
end
class RatingEvent < ActiveRecord::Base
end
class PostRatingObserver < ActiveRecord::Base
observer :post
def after_save
2009-10-06 15:02:58.980::WARN: Error for /quadran/
java.lang.NoClassDefFoundError: org/jruby/RubyTempfile
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at org.jruby.RubyModule$MethodClumper.clump(RubyModule.java:574)
at org.jruby.anno.TypePopulator$DefaultTypePopulator.populate(TypePopulator.java:47)
at org.jruby.RubyModule.defineAnnotatedMethodsIndividually(RubyModule.java:660)
at org.jruby.RubyModule.defineAnnotatedMethods(RubyModule.java:562)
at org.jruby.rack.input.RackBaseInput.getClass(RackBaseInput.java:36)
World do
session = Webrat::MechanizeSession.new
session.extend(Webrat::Matchers)
session.extend(Webrat::HaveTagMatcher)
session
end
Feature: Login # features/login.feature
In order to secure access to the application.
I want all users to have to login.
Scenario: Present login page to unauthenticated users. # features/login.feature:5
Given I have an account for "test" # features/step_definitions/global_steps.rb:3
And I go to "account root" # features/step_definitions/webrat_steps.rb:6
Then I should see "Login" # features/step_definitions/webrat_steps.rb:94
expected: /Login/m,
got: "<html><body>You are being <a href=\"http://test.localhost/session/new\">redirected</a>.</body></html>" (using =~)
Diff: