SlideShare a Scribd company logo
API-based client/serverAPI-based client/server
applications with TDD andapplications with TDD and
ActiveResourceActiveResource
Wolfram ArnoldWolfram Arnold
www.rubyfocus.bizwww.rubyfocus.biz
In collaboration with:In collaboration with:
Kurt SnyderKurt Snyder
papercheck.compapercheck.com
marakana.commarakana.com
Database-backedDatabase-backed
DB
Application
ActiveRecord
SQL
API-backedAPI-backed
Client
Application
ActiveResource
Server
Application
API
JSON
DB
SQL
Tradeoffs?Tradeoffs?
DB-backed
Fast
ActiveRecord well developed
Complex relationships possible
Limited scalability—tight coupling
API-backed
Extra network & server latency
Complex relationships more difficult
Scales well to different front-ends—loose coupling
Client
Application
(Flash or JS)
Frontend ScalabilityFrontend Scalability
Client
Application
ActiveResource
Server
Application
API
JSON
DB
SQL
Client
Application
(Mobile)
Rails ActiveResourceRails ActiveResource
Model objects that behaves ActiveRecord objects
Maps CRUD operations to RESTful API
No Associations
No Validations (added in Rails 3)
Rougher around the edges than ActiveRecord
From CRUD to RESTFrom CRUD to REST
class Person < ActiveResource::Base
site “http://server.example.com/people”
format :json
end
Person.create(:name => “Joe”)
→ POST /people, {'name':'Joe'}
Person.find(4)
→ GET /people/4
Resourceful RoutesResourceful Routes
map.resources :people (in config/routes.rb)
people_path, people_url “named route methods”
GET /people → “index” action
POST /people → “create” action
new_person_path, new_person_url
GET /people/new → “new” action
edit_person_path, edit_person_url
GET /people/:id/edit → “edit” action with ID
person_path, person_url
GET /people/:id → “show” action with ID
PUT /people/:id → “update” action with ID
DELETE /people/:id → “destroy” action with ID
Hyperactive ResourceHyperactive Resource
http://github.com/taryneast/hyperactiveresource
Adds Associations
Supports nested routes
/people/5/addresses/3
But: Cannot mix nested and non-nested routes for the
same resource
Adds Validations
Let's do some codingLet's do some coding
Demo
RESTful Person Server API with JSON
HyperactiveResource-based client
TDD anyone?TDD anyone?
DB
Application
ActiveRecord
SQL
RSpec model tests
with fixtures, factories
Test Database
with transaction support
TDD ActiveRecord StyleTDD ActiveRecord Style
it “should create the object” do
lambda {
Person.create(:first_name => “Joe”)
}.should change(Person, :count).by(1)
end
it “should destroy the object” do
p = Factory.create(:person)
lambda {
p.destroy
}.should change(Person, :count).by(-1)
end
API-backedAPI-backed
Client
Application
ActiveResource
Server
Application
API
JSON
DB
SQL
RSpec model test
Test Database
on
Test Server
instance!
Mocks anyone?Mocks anyone?
FakeWeb gem: http://github.com/chrisk/fakeweb
FakeWeb.register_uri(:get,
"http://server.example.com/people",
:body => "Hello World!")
Body is the mock object.
It should simulate the server response.
Great solution if it's a 3rd
party server.
Problems with Mocks?Problems with Mocks?
If the server code is under our control...
What happens if the server API changes but the
mock doesn't?
What process keeps the simulated server
responses and the actual API in sync?
Better ideas?
Beyond MocksBeyond Mocks
Remote Specs
Rely on remote server running (in test environment)
Mechanism to set up data
Mechanism to inspect data
Mechanism to clean up data
Distributed Ruby “DRb”Distributed Ruby “DRb”
Client
Application
DRb Client
Server
Application
DRb Server
DRb
Remote
Method
Invocation
foo(args)
foo(args)
Demo DRb
Gotcha'sGotcha's
ActiveResource::Base.include_root_in_json
after_initialize hook for starting DRb server
:id problem for Objects, via DRb
Need to run server in test mode
Ideas/Questions:
Front Object in DRb?
rake task to start/stop server—reliably find process?
DRb port inflation—better way?
SummarySummary
Server application with REST controller
Client application with ActiveResource
Use DRb to:
test objects
inquire “actual” data
TDD with ActiveResource
BizConfBizConf
Aug 4-6, 2010
Amelia Island, FL
Discount code: WOLF
for 43% off
http://bizconf.org?
coupon=WOLF
Rails & Web App
Professionals, Entrepreneurs,
Consultants
Small group
Network with Who's Who
Organized by Obie
Fernandez of Hashrocket
Highlight: David Allen

More Related Content

PDF
2010-07-19_rails_tdd_week1
PDF
2011-02-03 LA RubyConf Rails3 TDD Workshop
PDF
Consuming REST services with ActiveResource
PDF
Real World Fun with ActiveResource
PDF
React && React Native workshop
PDF
Ruby performance - The low hanging fruit
PDF
Modern Functional Fluent ColdFusion REST Apis
ODP
Scal`a`ngular - Scala and Angular
2010-07-19_rails_tdd_week1
2011-02-03 LA RubyConf Rails3 TDD Workshop
Consuming REST services with ActiveResource
Real World Fun with ActiveResource
React && React Native workshop
Ruby performance - The low hanging fruit
Modern Functional Fluent ColdFusion REST Apis
Scal`a`ngular - Scala and Angular

What's hot (20)

PDF
From ActiveRecord to EventSourcing
PDF
The CQRS diet
ODP
Introduction to Scala JS
PPT
Jasmine - A BDD test framework for JavaScript
PDF
Cooking your Ravioli "al dente" with Hexagonal Architecture
ODP
Introduction to Swagger
PDF
Serverless Architecture - A Gentle Overview
PDF
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
PPTX
API Test Automation Using Karate (Anil Kumar Moka)
PDF
Deploying a Location-Aware Ember Application
PPTX
django Forms in a Web API World
PPTX
RESTful API Design Best Practices Using ASP.NET Web API
PDF
アドテク×Scala @Dynalyst
PDF
Test-Driven Documentation for your REST(ful) service
PDF
Akka in Practice: Designing Actor-based Applications
PPTX
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
PDF
Cqrs api
PDF
Behavior Driven Development with Cucumber
PDF
Crash Course in AngularJS + Ionic (Deep dive)
PDF
APIs: A Better Alternative to Page Objects
From ActiveRecord to EventSourcing
The CQRS diet
Introduction to Scala JS
Jasmine - A BDD test framework for JavaScript
Cooking your Ravioli "al dente" with Hexagonal Architecture
Introduction to Swagger
Serverless Architecture - A Gentle Overview
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
API Test Automation Using Karate (Anil Kumar Moka)
Deploying a Location-Aware Ember Application
django Forms in a Web API World
RESTful API Design Best Practices Using ASP.NET Web API
アドテク×Scala @Dynalyst
Test-Driven Documentation for your REST(ful) service
Akka in Practice: Designing Actor-based Applications
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
Cqrs api
Behavior Driven Development with Cucumber
Crash Course in AngularJS + Ionic (Deep dive)
APIs: A Better Alternative to Page Objects
Ad

Similar to 2010 07-20 TDD with ActiveResource (20)

PDF
Ibm_interconnect_restapi_workshop
PDF
Seattle StrongLoop Node.js Workshop
PDF
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
PPT
Ruby On Rails
PPTX
Web 2.0 Development with IBM DB2
PPTX
StrongLoop Overview
PDF
Beginning MEAN Stack
PDF
Getting Started with the Node.js LoopBack APi Framework
PPTX
Best of Microsoft Dev Camp 2015
PPTX
The API Facade Pattern: Common Patterns - Episode 2
PPTX
REST-Enabling Enterprise Data in the Mobile Era
PPTX
Connect js nodejs_api_shubhra
PPTX
Triangle Node Meetup : APIs in Minutes with Node.js
PPTX
Serverless Generative AI on AWS, AWS User Groups of Florida
PDF
Scale, baby, scale!
PDF
Modern Architectures with Spring and JavaScript
PPTX
Building an aws sdk for Perl - Granada Perl Workshop 2014
PDF
Serverless GraphQL for Product Developers
KEY
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Ibm_interconnect_restapi_workshop
Seattle StrongLoop Node.js Workshop
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Ruby On Rails
Web 2.0 Development with IBM DB2
StrongLoop Overview
Beginning MEAN Stack
Getting Started with the Node.js LoopBack APi Framework
Best of Microsoft Dev Camp 2015
The API Facade Pattern: Common Patterns - Episode 2
REST-Enabling Enterprise Data in the Mobile Era
Connect js nodejs_api_shubhra
Triangle Node Meetup : APIs in Minutes with Node.js
Serverless Generative AI on AWS, AWS User Groups of Florida
Scale, baby, scale!
Modern Architectures with Spring and JavaScript
Building an aws sdk for Perl - Granada Perl Workshop 2014
Serverless GraphQL for Product Developers
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Ad

Recently uploaded (20)

PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
1. Introduction to Computer Programming.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Approach and Philosophy of On baking technology
PDF
August Patch Tuesday
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
project resource management chapter-09.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Encapsulation theory and applications.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
A comparative study of natural language inference in Swahili using monolingua...
1. Introduction to Computer Programming.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Approach and Philosophy of On baking technology
August Patch Tuesday
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Hybrid model detection and classification of lung cancer
Accuracy of neural networks in brain wave diagnosis of schizophrenia
OMC Textile Division Presentation 2021.pptx
project resource management chapter-09.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Heart disease approach using modified random forest and particle swarm optimi...
Encapsulation theory and applications.pdf
Hindi spoken digit analysis for native and non-native speakers
Web App vs Mobile App What Should You Build First.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf

2010 07-20 TDD with ActiveResource