Sha256: 9100b48c1c02ff7b1ca46bc1fdbb9c13dfdfebebdc987889c6b669d21da5c20d

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require "spec_helper"

describe "Captcha" do
  before :all do
    class TheController
      inherit Rad::Controller::Http, Rad::Controller::Captcha

      def action
        render inline: 'ok'
      end
    end
  end
  after(:all){remove_constants :TheController}

  before do
    rad.captcha.stub!(:enabled).and_return(true)

    @request = Rad::Http::Request.stub
    @request.stub!(:from_browser?).and_return(true)

    @params = Rad::Conveyors::Params.new

    @controller = TheController.new
    @controller.stub!(:request).and_return(@request)
    @controller.stub!(:params).and_return(@params)
  end

  it "should allow get for anyone" do
    @request.stub!(:get?).and_return(true)

    rad.user = Factory.build :anonymous
    @controller.call(:action).should == 'ok'

    rad.user = Factory.build :registered
    @controller.call(:action).should == 'ok'
  end

  it "shouldn't allow non-get for anonymous" do
    @request.stub!(:get?).and_return(false)

    rad.user = Factory.build :anonymous
    -> {@controller.call(:action)}.should raise_error(UserError)

    rad.user = Factory.build :registered
    @controller.call(:action).should == 'ok'
  end

  it "should display captcha form for anonymous if format is :js" do
    @request.stub!(:get?).and_return(false)
    @params.format = 'js'
    rad.captcha.stub!(:verify).and_return(false)
    rad.user = Factory.build :anonymous
    @controller.stub!(:render).and_return('form')

    @controller.call(:action).should == 'form'
  end

  it "should allow anonymous access if it solved captcha" do
    @request.stub!(:get?).and_return(false)
    @params.format = 'js'
    rad.captcha.stub!(:verify).and_return(true)
    rad.user = Factory.build :anonymous

    @controller.call(:action).should == 'ok'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rad_kit-0.0.10 spec/controller/captcha_spec.rb
rad_kit-0.0.9 spec/controller/captcha_spec.rb