Sha256: 6338bba4141c7df33df3f0b865dbf7e566369b7d8736d057ba335dfa46fbd928

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require File.expand_path('../../../../spec/helper', __FILE__)

class SpecSimpleCaptcha < Ramaze::Controller
  helper :simple_captcha
  map '/'

  def ask_question
    question = simple_captcha
  end

  def answer_question(with)
    check_captcha(with) ? 'correct' : 'wrong'
  end
end

class SpecCustomCaptcha < SpecSimpleCaptcha
  map '/fish'

  trait :captcha => lambda{
    ["the answer to everything", 42]
  }
end

describe Ramaze::Helper::SimpleCaptcha do
  behaves_like :rack_test

  should 'ask question' do
    get('/ask_question')
    question = last_response.body
    question.should =~ /^\d+ [+-] \d+$/

    lh, m, rh = question.split
    answer = lh.to_i.send(m, rh.to_i)

    get("/answer_question/#{answer}").body.should == 'correct'
  end

  should 'ask custom question' do
    get('/fish/ask_question').body.should == 'the answer to everything'
    get('/fish/answer_question/42').body.should == 'correct'
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
Pistos-ramaze-2009.06.12 spec/ramaze/helper/simple_captcha.rb
manveru-ramaze-2009.07 spec/ramaze/helper/simple_captcha.rb
ramaze-2011.12.28 spec/ramaze/helper/simple_captcha.rb
ramaze-2011.10.23 spec/ramaze/helper/simple_captcha.rb
ramaze-2011.07.25 spec/ramaze/helper/simple_captcha.rb
ramaze-2011.01.30 spec/ramaze/helper/simple_captcha.rb
ramaze-2011.01 spec/ramaze/helper/simple_captcha.rb
ramaze-2010.06.18 spec/ramaze/helper/simple_captcha.rb
ramaze-2010.04.04 spec/ramaze/helper/simple_captcha.rb
ramaze-2010.04 spec/ramaze/helper/simple_captcha.rb
ramaze-2010.03 spec/ramaze/helper/simple_captcha.rb
ramaze-2010.01 spec/ramaze/helper/simple_captcha.rb
ramaze-2009.10 spec/ramaze/helper/simple_captcha.rb
ramaze-2009.07 spec/ramaze/helper/simple_captcha.rb