Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
require File.dirname(__FILE__) + '/../spec_helper' include PersonSpecHelper include EmailConfirmationSpecHelpers describe PeopleController, ": handling POST /people" do before(:each) do setup_person_mock end def do_post post :create, {:person => valid_person_attributes, :debug => true} end it "should create a new person" do Person.should_receive(:find).with(anything(), duck_type(:keys,:values)).and_return(nil) lambda { do_post }.should change { Person.count }.by(1) end end describe PeopleController, ": Requesting /people.xml using POST with valid user" do integrate_views before(:each) do setup_person_mock end def do_post @request.env["HTTP_ACCEPT"] = "application/xml" post :create, :person => valid_person_attributes end it "should not have a body" do do_post response.should_not have_tag(:xml) response.should_not have_tag(:html) end end describe PeopleController, ": Requesting /people.xml using POST with invalid user" do integrate_views before(:each) do setup_person_mock end def do_post accept("application/xml") post :create, :person => (valid_person_attributes.except :first_name) end it "should have an errors tag with one nested error tag" do do_post response.should have_tag("errors") do with_tag("error") end end end ############### Move to a model test ################ # describe PeopleController, ": Requesting /people/1.xml" do # integrate_views # # before(:each) do # setup_person_mock(:to_xml => 'xml') # end # # def do_get # @request.env["HTTP_ACCEPT"] = "application/xml" # get :show, :id => "1" # end # # it "should return person_id = 1" do # do_get # response.body.should have_tag("person") do # with_tag("id", "1") # end # end # # it "should be populated with the correct name fields" do # do_get # response.should have_tag("person") do # with_tag("first-name", "John") # with_tag("last-name", "Goodsen") # end # end # end #################################################### # Tests brought from the users controller spec # necessary for User refactor into Person/Account #################################################### describe "non-existant person", :shared => true do it "should have status of 404 with non-existant object" do do_method @response.response_code.should == 404 end end describe PeopleController,": Requesting /people using GET" do # /people with no id maps to People#show def do_get get :index end it_should_redirect_to(:login) it_should_set_flash end describe PeopleController,": Requesting /people using GET while logged in" do before(:each) do setup_person_mock end def do_get get :index, {:id => @request.session[:person]} end it_should_redirect_to(:home) it_should_set_flash end describe PeopleController,": Requesting /people.xml using GET while logged in" do before(:each) do setup_person_mock end def do_get accept("application/xml") get :index end it "should populate people to be rendered" do do_get assigns[:people].should_not be_nil end end describe PeopleController,": Requesting /people/new using GET" do before(:each) do setup_person_mock end def do_get get :new end it_should_be_success it_should_render(:new) end describe PeopleController,": Requesting /people/1;edit using GET when logged in" do before(:each) do setup_person_mock(:id => 1) end def do_get get :edit, { :id => "1" } end it "should fail if current person doesn't match" do controller.should_receive(:current_person).at_least(1).and_return(Person.new) do_get response.should be_redirect end it "should render edit template" do do_get response.should render_template(:edit) end it "should assign the found Person for the view" do do_get assigns[:current_person].should equal(@person) end end describe PeopleController,": PeopleController create (POST -> /people)" do before(:each) do @mockperson = null_mock_model( Person, :save => true) @mockconfirmation = null_mock_model( PasswordResetConfirmation) Person.stub!(:new).and_return(@mockperson) PersonNotifier.stub!(:deliver_signup_notification).and_return(true) controller.stub!(:captcha_valid?).and_return(true) end def do_post post :create, { :person => valid_person_attributes } end it "should create a new person" do Person.should_receive(:new).with(valid_person_attributes).and_return(@mockperson) do_post end it "should save new person" do @mockperson.should_receive(:save).and_return(true) do_post end it "should not send a Password Reset Confirmation" do PersonNotifier.should_not_receive(:deliver_password_reset_confirmation) do_post end it "should send a signup notification" do PersonNotifier.should_receive(:deliver_signup_notification) do_post end it "should re-render registration form if captcha is wrong" do controller.stub!(:captcha_valid?).and_return(false) do_post response.should render_template(:new) end it "should be redirect to person's home page" do do_post response.should redirect_to(person_path(@mockperson)) end it_should_set_flash it "should re-render new.rhtml if the save fails" do @mockperson.stub!(:save).and_return(false) do_post response.should_not be_redirect response.should render_template( :new ) end it "should set session[:person]" do do_post session[:person].should_not be_nil end end describe PeopleController,": Requesting stuff from people we shouldn't get" do before(:each) do setup_user_mock end it "should not show people index" do get :index, {} flash[:notice].should eql("Requested page was not found") response.should be_redirect end def do_method controller.should_receive(:current_person).at_least(:once).and_return(@person) Person.should_receive(:find).with("5").and_raise(ActiveRecord::RecordNotFound.new) get :show, {:id => 5} end #it_should_behave_like "non-existant person" # it "should redirect to homepage for non-existant people" do # get :show, { :id => "value" } # response.should render_template('people/show') # end end # # describe "PeopleController: update (PUT -> /people/1)" do # # # before(:each) do # setup_user_mock(:id => 1) # end # # def do_update # put :update, {:id => "1", :person => {:first_name => "Bill"}} # end # # it "should find the current person" do # Person.should_receive(:find).and_return(@person) # do_update # end # # it "should redirect because person5 is attempting to update person1" do # @person.stub!(:id).and_return(5) # do_update # response.should be_redirect # end # # it "should update attributes of the found person" do # @person.should_receive(:update_attributes).and_return(true) # do_update # end # # it "should retrieve update name" do # @person.should_receive(:name).and_return("Bill Doe") # do_update # end # # it "should set flash :notice to 'updated' message" do # do_update # flash[:notice].should match(/updated/) # end # end # # describe "PeopleController: change_email update (PUT -> /people/1?commit=Change+Email)" do # # # before(:each) do # @new_email = 'test2@testy.com' # setup_mock_user(:id => 1) # @mock_email_confirmation = null_mock_model(ChangeEmailConfirmation, :new_email => "test@testy.com") # ChangeEmailConfirmation.stub!(:new).and_return(@mock_email_confirmation) # end # # def do_update # put :update, {:id => "1", :commit => 'Change Email', # :current_user => { :email => @new_email, # :email_confirmation => @new_email } } # end # # it "should find the current person" do # Person.should_receive(:find).and_return(@person) # do_update # end # # it "should redirect" do # @session = { :person => 3 } # @person.stub!(:id).and_return(3) # do_update # response.should be_redirect # end # # it "should create a ChangeEmailConfirmation object" do # ChangeEmailConfirmation.should_receive(:new).and_return(@mock_email_confirmation) # do_update # end # # it "should save the ChangeEmailConfirmation record" do # @mock_email_confirmation.should_receive(:save).and_return(true) # do_update # end # # it "should render a confirmation page to the person" do # do_update # response.should render_template('confirm') # end # # it "should set error in flash notice on invalid email" do # controller.stub!(:valid_email?).and_return(false) # do_update # flash[:error].should match(/Could not change email./) # end # # it "should render back to edit page on invalid email" do # controller.stub!(:valid_email?).and_return(false) # do_update # response.should render_template(:edit) # end # # end # # describe "PeopleController: change_password update (PUT -> /people/1?commit=Change+Password)" do # # # before(:each) do # @new_password = 'newpassword' # setup_mock_user(:id => 1) # end # # def do_update # put :update, {:id => "1", :commit => 'Change Password', # :old_password => valid_person_attributes['password'], # :current_user => { :password => @new_password, # :password_confirmation => @new_password } } # end # # it "should succeed" do # Person.should_receive(:find).and_return(@person) # @person.should_receive(:authenticated?).and_return(true) # @person.should_receive(:update_attributes).and_return(true) # do_update # end # # it "should find the current person" do # Person.should_receive(:find).and_return(@person) # do_update # end # # it "should redirect" do # @session = { :person => 3 } # @person.stub!(:id).and_return(3) # do_update # response.should be_redirect # end # # it "should check to make sure that the old password entered matches the person's password" do # @person.should_receive(:authenticated?).and_return(true) # do_update # end # # it "with commit = 'Change Password' should assign password and password_confirmation in Person model" do # @person.should_receive(:update_attributes).and_return(true) # do_update # end # # it "should return to the edit page" do # do_update # response.should be_redirect # end # # it "should set flash to success message" do # do_update # flash[:notice].should match(/password has been changed/i) # end # # it "should set error in flash notice with blank password" do # put :update, {:id => "1", :commit => 'Change Password', # :old_password => '', # :current_user => { :password => @new_password, # :password_confirmation => @new_password } } # flash[:error].should match(/Please enter your current password/) # end # # it "should set error in flash notice with bad old_password" do # @person.stub!(:authenticated?).and_return(false) # do_update # flash[:error].should match(/Old Password doesn't match/) # end # # it "should set error in flash notice with blank new password" do # put :update, {:id => "1", :commit => 'Change Password', # :old_password => valid_person_attributes['password'], # :current_user => { :password => '', # :password_confirmation => @new_password } } # flash[:error].should match(/New password must be entered/) # end # end include PersonCreditcardValidateSpecHelper describe PeopleController, ": Signing up for a new subscription" do before(:each) do setup_person_mock Person.stub!(:purchase_subscription) end it "should have a link from the main page that links to a subscription page" do get :purchase_subscription, {:id =>1} response.should render_template(:purchase_subscription) end it "should redirect to success page upon positive validation" do @person.stub!(:create_paid_subscription) attributes = valid_person_creditcard_validate_attributes attributes["exp(3i)"] = nil attributes["exp(2i)"] = attributes.delete(:exp_month) attributes["exp(1i)"] = attributes.delete(:exp_year) post :purchase_subscription, {:id =>1, :person_creditcard_validate => attributes} response.should redirect_to( person_path(@person) ) end it "should re-render page with error callouts if validation fails" do post :purchase_subscription, {:id =>1, :person_creditcard_validate => {}} response.should render_template(:purchase_subscription) flash.now[:error].should match(/denied/i) end end describe PeopleController ,"#confirm_email: Clicking link from email before expiration (GET /confirm/email/<code>)" do before(:each) do @confirmation_code = '123456' @email = 'test@person.com' @mock_person = mock_model(Person, :save => true, :email => @email) @mock_email_confirmation = mock_model(ChangeEmailConfirmation, :person => @mock_person, :new_email => @email) ChangeEmailConfirmation.stub!(:find_by_confirmation_code).and_return(@mock_email_confirmation) @mock_person.stub!(:change_email_confirmation).and_return(@mock_email_confirmation) @mock_person.stub!(:email=) { |val| return val } end def do_get get :confirm_email, { :confirmation_code => @confirmation_code } end it "should receive a confirmation_code in params (from incoming link)" do do_get params[:confirmation_code].should eql(@confirmation_code) end it "should find a matching ChangeEmailConfirmation record matching confirmation_code" do ChangeEmailConfirmation.should_receive(:find_by_confirmation_code).with(@confirmation_code).and_return(@mock_email_confirmation) do_get end it "should find a valid Person for the ChangeEmailConfirmation found" do @mock_email_confirmation.should_receive(:person).and_return(@mock_person) do_get end it "should set the Person's email to the saved new email" do @mock_email_confirmation.should_receive(:new_email).and_return(@email) @mock_person.should_receive(:email=).with(@email).and_return(@email) do_get end it "should successfully save the updated Person" do @mock_person.should_receive(:save).and_return(true) do_get end it "should set flash to an 'email changed' message" do do_get flash[:notice].should match(/email address has been changed/i) end it "should redirect back to the Person home page" do do_get response.should redirect_to(person_path(@mock_person.id)) end it "should redirect to /login if a matching EmailConfirmation cannot be found" do ChangeEmailConfirmation.stub!(:find_by_confirmation_code).and_return(nil) do_get response.response_code.should == 404 end end
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Google Docs - Exploit
3 min ago | 0.27 KB
SwapEngine Bug [build 1.3]
17 min ago | 0.27 KB
This month smells like money
CSS | 30 min ago | 0.27 KB
✅ Changelly.com Exploit
43 min ago | 0.27 KB
Trading method
CSS | 56 min ago | 0.27 KB
AI METHODS
7 hours ago | 0.29 KB
Untitled
7 hours ago | 0.29 KB
Untitled
7 hours ago | 0.29 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!