5. La
promesse
Petit pattern
est
maison
souvent
alléchante
Spring
JSF
RichFaces HTML
hagerstenguy
6. Code applicatif
Couches
d’abstraction
Et la
HTML / JS /CSS
réalité
parfois
écoeurante lifeontheedge
7. « Ruby on Rails is an open-source web framework
that’s optimized for programmer happiness and
sustainable productivity. It let’s write beautiful code
by favoring convention over configuration. »
8. « Ruby on Rails is an open-source web framework
that’s optimized for programmer happiness and
programmer
sustainable productivity. It let’s write beautiful code
by favoring convention over configuration. »
18. fichier app/controllers/books_controller.rb
class BooksController < ApplicationController
def index
@books = Book.all
end
end
class BooksController < ApplicationController
def index
render :json => @books
end
end
19. fichier app/controllers/books_controller.rb
class BooksController < ApplicationController
def index
@books = Book.all
end
end
class BooksController < ApplicationController
def index
render :json => @books
end
end
class BooksController < ApplicationController
def index
render :xml => @books
end
end
20. Un framework fait
pour le web
Controlleur
Templating
Routing REST
ActiveRecord
29. fichier app/controllers/book_controller.rb
class BookController < ApplicationController
# POST /book/1 or POST /book/1.xml
def create
end
# GET /book or GET /book
def show
end
# PUT /book/1 or PUT /book/1.xml
def update
end
# DELETE /book/1 or DELETE /book/1.xml
def destroy
end
end
30. fichier config/routes.rb
MyApp::Application.routes.draw do |map|
resources :people
resources :book
resources :people, :except => :destroy
resources :people do
member do
get 'short_profile'
post 'fire'
end
end
namespace :admin do
resources :people
end
match 'people/:firstname/:lastname' => 'people#show'
end
31. fichier config/routes.rb
MyApp::Application.routes.draw do |map|
resources :people
resources :book
resources :people, :except => :destroy
resources :book, :except => :destroy
resources :people do
member do
get 'short_profile'
post 'fire'
end
end
namespace :admin do
resources :people
end
match 'people/:firstname/:lastname' => 'people#show'
end
32. fichier config/routes.rb
MyApp::Application.routes.draw do |map|
resources :people
resources :book
resources :people, :except => :destroy
resources :book, :except => :destroy
resources :people do
resources do
member :book do
get 'short_profile'
member do
post 'fire'
get 'short_description'
end
end
end
end
namespace :admin do
resources :people
end
match 'people/:firstname/:lastname' => 'people#show'
end
33. fichier config/routes.rb
MyApp::Application.routes.draw do |map|
resources :people
resources :book
resources :people, :except => :destroy
resources :book, :except => :destroy
resources :people do
resources do
member :book do
get 'short_profile'
member do
post 'fire'
get 'short_description'
end
end
end
end
namespace :admin do
namespace :admin do
resources :people
resources :book
end
end
match 'people/:firstname/:lastname' => 'people#show'
end
34. fichier config/routes.rb
MyApp::Application.routes.draw do |map|
resources :people
resources :book
resources :people, :except => :destroy
resources :book, :except => :destroy
resources :people do
resources do
member :book do
get 'short_profile'
member do
post 'fire'
get 'short_description'
end
end
end
end
namespace :admin do
namespace :admin do
resources :people
resources :book
end
end
match 'people/:firstname/:lastname' => 'people#show'
match 'book/:kind/:keyword' => 'book#search'
end
35. Un framework fait
pour le web
Controlleur
Templating
Routing REST
ActiveRecord
36.
37. Run commande shell
rails generate model book title:string description:string
rake db:migrate
38. Run commande shell
rails generate model book title:string description:string
rake db:migrate
You
get fichiers app/model/book.rb
class Book < ActiveRecord::Base
end
39. Run commande shell
rails generate model book title:string description:string
rake db:migrate
You
get fichiers app/model/book.rb
class Book < ActiveRecord::Base
end
You
get fichiers db/schema.rb
ActiveRecord::Schema.define(:version => 20101007134936) do
create_table "books", :force => true do |t|
t.string "title"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end
end
40. Run commande shell
rails generate model book title:string description:string
rake db:migrate
You
get fichiers app/model/book.rb
class Book < ActiveRecord::Base
end
You
get fichiers db/schema.rb
ActiveRecord::Schema.define(:version => 20101007134936) do
create_table "books", :force => true do |t|
t.string "title"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Run rails console
Book.new(:title => "Fondation", :description => "a fantastic book").save
Book.find_all
Book.find_by_title("Fondation")
Book.where({:title => "Fondation", :description => "a fantastic book"})
43. Unit Testing Integration Testing
Functional Testing
44. Unit Testing Integration Testing
test "should
not save book
book = Book.n without title
ew " do
assert !book.
save, "Saved
end book without
title"
Functional Testing
45. Unit Testing Integration Testing
test "should
not save book
book = Book.n without title
ew " do
assert !book.
save, "Saved
end book without
title"
do
t i ndex"
sho uld ge
test "
dex ss
g et :in nse :succe s)
_respo igns (:post
assert il ass
t_n
ass ert_no
end
Functional Testing
46. Unit Testing Integration Testing
class
UserFl
test "should Action owsTes
not save book Contro t <
without title fixtur ller::
book = Book.n " do es :us Integr
ew ers ationT
est
assert !book.
save, "Saved test "
end book without login
title" and br
# logi owse s
n via ite" d
https! https o
get "/
login"
assert
_respo
nse :s
uccess
post_v
login" ia_red
, :use irect
rname "/
users( =>
inde x" do users(
:avs).
userna
o ul d get :avs). me, :p
asswor
st "sh
passwo d =>
te assert rd
dex ss _equal
g et :in onse :succe ts)
assert
_equal
'/welc
ome',
sert _resp signs (:pos flash[
:notic 'Welco path
as as me avs
t_n ot_nil e] !',
asser
https!
(false
end get "/ )
posts/
assert all"
_respo
assert nse :s
assign uccess
end s(:pro
ducts)
end
Functional Testing
55. freeze_time = Time.now + 200.days
Timecop.freeze(freeze_time) do
assert_equal freeze_time, Time.now
sleep(100)
assert_equal freeze_time, Time.now
end
github.com/jtrupiano/timecop
56. c page
onent t o my publi
itter comp page
dd a tw ugh an o cto public
Feature: A tweet thro
are my
In o rder to sh y page
ymous o cto ee my t witts on m
As an anon tter acc ount and s
set my twi
I want to
count
Set my twitter ac
Scenario: avier
me is Ch ristian Bl
G iven my na
ebook
on octofac dy exist
And I am e, cblav ier, alrea
And my public pag eet"
ed "Her e is my tw
And I have twitt
page
hen I go to edit my t" with "c
blavier"
W accoun
i n "twitter
And I fill de Christi
an"
I press "U
pdate" publique
And enue su r la page
uld see "Bienv
Then I sho Here is my
tweet"
ld see "
And I shou