SlideShare uma empresa Scribd logo
1 de 64
Ruby On Rails,
     vu d’un Javaiste

Paris JUG, 12 octobre 2010
Christian Blavier
cblavier@octo.com
Sponsors Platiniums 2010
Moi
en
bref

  Architecte
chez
OCTO

      depuis
2004
       Expert
Java
   twi?er.com/cblavier
blog.octo.com/author/cbl/
Moi
en
bref

  Architecte
chez
OCTO

      depuis
2004
       Expert
Java
   twi?er.com/cblavier
blog.octo.com/author/cbl/
La
                       promesse
Petit pattern
                       est
   maison
                       souvent
                       alléchante

Spring

   JSF


  RichFaces     HTML

 hagerstenguy
Code applicatif




                           Couches
                           d’abstraction




      Et la
              HTML / JS /CSS
    réalité
    parfois
écoeurante                      lifeontheedge
« 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. »
« 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. »
Views



                  Models
Controllers

              ActiveRecord


               Database
Manipulation de dates

      Closures
Tasty Ruby

Manipulation de dates

      Closures
> now = DateTime.now
 => Thu, 07 Oct 2010 14:05:43 +0200


> tomorrow = now + 1.day
 => Fri, 08 Oct 2010 14:05:43 +0200


> one_week_ago = 7.days.ago
 => Thu, 30 Sep 2010 14:06:09 +0200
Tasty Ruby

Manipulation de dates

      Closures
> ["one", "two", "three"].map { |word|
     word.upcase
  }
=> ["ONE", "TWO", "THREE"]



> [1, 2, 3, 4, 5].find_all { |item| item > 3 }
=> [4, 5]
Controlleur
 Templating
Routing REST
ActiveRecord
Un framework fait
   pour le web
     Controlleur
     Templating
    Routing REST
    ActiveRecord
fichier app/controllers/books_controller.rb
  class BooksController < ApplicationController
    def index
      @books = Book.all
    end
  end
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
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
Un framework fait
   pour le web
     Controlleur
     Templating
    Routing REST
    ActiveRecord
fichier app/views/books/index.html.erb
   <h1>Listing Books</h1>
   <table>
     <tr>
       <th>Title</th>
       <th>Summary</th>
       <th></th>
       <th></th>
       <th></th>
     </tr>
   <% @books.each do |book| %>
     <tr>
       <td><%= book.title %></td>
       <td><%= book.content %></td>
       <td><%= link_to 'Show', book %></td>
       <td><%= link_to 'Edit', edit_book_path(book) %></td>
       <td><%= link_to 'Remove', book,:method => :delete %></td>
     </tr>
   <% end %>
   </table>
   <%= link_to 'New book', new_book_path %>
fichier app/views/books/index.html.haml
   %h1 Listing Books
   %table
     %tr
       %th Title
       %th Summary
       %th
       %th
       %th
     - @books.each do |book|
       %tr
          %td= book.title
          %td= book.content
          %td= link_to 'Show', book
          %td= link_to 'Edit', edit_book_path(book)
          %td= link_to 'Remove', book,:method => :delete
   = link_to 'New book', new_book_path
fichier app/views/books/index.html.haml
   %h1 Listing Books
   %table
     %tr
       %th Title
       %th Summary
       %th
       %th
       %th
     - @books.each do |book|
       %tr
          %td= book.title
          %td= book.content
          %td= link_to 'Show', book
          %td= link_to 'Edit', edit_book_path(book)
          %td= link_to 'Remove', book,:method => :delete
   = link_to 'New book', new_book_path


  Haml takes your gross, ugly templates and replaces them with veritable
  Haiku. Haml is based on one primary principle : markup should be
  beautiful.
{markup haiku}            {style with attitude}
http://haml-lang.com/   http://sass-lang.com/
Un framework fait
   pour le web
     Controlleur
     Templating
    Routing REST
    ActiveRecord
POST   /books/create
GET    /books/show/1
POST   /books/update/1
POST   /books/destroy/1
POST     /books/
GET      /books/1
PUT      /books/1
DELETE   /books/1
fichier config/routes.rb

MyApp::Application.routes.draw do |map|
    resources :book
end
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
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
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
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
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
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
Un framework fait
   pour le web
     Controlleur
     Templating
    Routing REST
    ActiveRecord
Run   commande shell
      rails generate model book title:string description:string
      rake db:migrate
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
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   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"})
Testing
Déploiement
Un framework fait
   pour l’agile


      Testing
    Déploiement
Unit Testing       Integration Testing




Functional Testing
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
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
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
require 'test/unit'
require 'mocha'
                                               Mocha
require 'fakeweb'

class MiscExampleTest < Test::Unit::TestCase




end




                                                 tmcnem
require 'test/unit'
require 'mocha'
                                                  Mocha
require 'fakeweb'

class MiscExampleTest < Test::Unit::TestCase

 def test_with_basic_mocha_stubbing
   product = Product.new
   product.stubs(:prices).returns([1000, 2000])
   assert_equal [1000, 2000], product.prices
 end




end




                                                    tmcnem
require 'test/unit'
require 'mocha'
                                                               Mocha
require 'fakeweb'

class MiscExampleTest < Test::Unit::TestCase

 def test_with_basic_mocha_stubbing
   product = Product.new
   product.stubs(:prices).returns([1000, 2000])
   assert_equal [1000, 2000], product.prices
 end

 def test_with_mocha_object_stubbing
   prices = [stub(:pence => 1000), stub(:pence => 2000)]
   product = Product.new
   product.stubs(:prices).returns(prices)
   assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
 end

end




                                                                     tmcnem
github.com/thoughtbot/factory_girl
fichier test/factories.rb
Factory.sequence :email do |n|
  "person#{n}@octo.com"
end

Factory.define :user do |u|
  u.first_name 'Robert'
  u.last_name 'Redford'
  u.email { Factory.next(:email) }
end




                                     github.com/thoughtbot/factory_girl
fichier test/factories.rb
Factory.sequence :email do |n|
  "person#{n}@octo.com"
end

Factory.define :user do |u|
  u.first_name 'Robert'
  u.last_name 'Redford'
  u.email { Factory.next(:email) }
end



fichier test/unit/a_test.rb
u = Factory :user
assert_equal "Robert", user.first_name
assert_equal "Redford", user.last_name

u = Factory :user,:email => "rob@gmail.com"
assert_equal "rob@gmail.com", u.email




                                              github.com/thoughtbot/factory_girl
fichier test/factories.rb
Factory.sequence :email do |n|
  "person#{n}@octo.com"
end

Factory.define :user do |u|
  u.first_name 'Robert'
  u.last_name 'Redford'
  u.email { Factory.next(:email) }
end



fichier test/unit/a_test.rb
u = Factory :user
assert_equal "Robert", user.first_name
assert_equal "Redford", user.last_name

u = Factory :user,:email => "rob@gmail.com"
assert_equal "rob@gmail.com", u.email



 Fixture replacement for
focused and readable tests
                                              github.com/thoughtbot/factory_girl
github.com/jtrupiano/timecop
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
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
Un framework fait
   pour l’agile


      Testing
    Déploiement
AfterTheWeekend
Rassembler, Enrichir, Imprimer vos photos d’évènements

               aftertheweekend.fr
                     @afterwee

  3ème prix du Startup Weekend !
Yapluka !
Yapluka !
Yapluka !
Yapluka !

Mais conteúdo relacionado

Mais procurados

Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentNicolas Ledez
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptEddie Kao
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuerycolinbdclark
 
Ingo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveIngo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveAxway Appcelerator
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptBrian Mann
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Ryan Weaver
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à RubyMicrosoft
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScriptJoost Elfering
 
SINATRA + HAML + TWITTER
SINATRA + HAML + TWITTERSINATRA + HAML + TWITTER
SINATRA + HAML + TWITTERElber Ribeiro
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 

Mais procurados (20)

Cucumber
CucumberCucumber
Cucumber
 
Ruby talk romania
Ruby talk romaniaRuby talk romania
Ruby talk romania
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
 
Ingo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep DiveIngo Muschenetz: Titanium Studio Deep Dive
Ingo Muschenetz: Titanium Studio Deep Dive
 
Ruby gems
Ruby gemsRuby gems
Ruby gems
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Hows Haml?
Hows Haml?Hows Haml?
Hows Haml?
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
 
SINATRA + HAML + TWITTER
SINATRA + HAML + TWITTERSINATRA + HAML + TWITTER
SINATRA + HAML + TWITTER
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 

Destaque

Session Spring et TDD du ParisJUG
Session Spring et TDD du ParisJUGSession Spring et TDD du ParisJUG
Session Spring et TDD du ParisJUGChristian Blavier
 
Industrialisation des développements Java
Industrialisation des développements JavaIndustrialisation des développements Java
Industrialisation des développements JavaChristian Blavier
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Destaque (6)

Wicket - JUG Lausanne
Wicket - JUG LausanneWicket - JUG Lausanne
Wicket - JUG Lausanne
 
Session Spring et TDD du ParisJUG
Session Spring et TDD du ParisJUGSession Spring et TDD du ParisJUG
Session Spring et TDD du ParisJUG
 
Industrialisation des développements Java
Industrialisation des développements JavaIndustrialisation des développements Java
Industrialisation des développements Java
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Semelhante a Rails vu d'un Javaiste

A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101Samantha Geitz
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 
The Django Book chapter 5 Models
The Django Book chapter 5 ModelsThe Django Book chapter 5 Models
The Django Book chapter 5 ModelsVincent Chien
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...Corley S.r.l.
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...Walter Dal Mut
 
TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyFabio Akita
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails IntroductionThomas Fuchs
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design PatternsTrevorBurnham
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amfrailsconf
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編Masakuni Kato
 

Semelhante a Rails vu d'un Javaiste (20)

A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
The Django Book chapter 5 Models
The Django Book chapter 5 ModelsThe Django Book chapter 5 Models
The Django Book chapter 5 Models
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em Ruby
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Rails vu d'un Javaiste

  • 1. Ruby On Rails, vu d’un Javaiste Paris JUG, 12 octobre 2010 Christian Blavier cblavier@octo.com
  • 3. Moi
en
bref Architecte
chez
OCTO
 depuis
2004 Expert
Java twi?er.com/cblavier blog.octo.com/author/cbl/
  • 4. Moi
en
bref Architecte
chez
OCTO
 depuis
2004 Expert
Java twi?er.com/cblavier blog.octo.com/author/cbl/
  • 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. »
  • 9. Views Models Controllers ActiveRecord Database
  • 11. Tasty Ruby Manipulation de dates Closures
  • 12. > now = DateTime.now => Thu, 07 Oct 2010 14:05:43 +0200 > tomorrow = now + 1.day => Fri, 08 Oct 2010 14:05:43 +0200 > one_week_ago = 7.days.ago => Thu, 30 Sep 2010 14:06:09 +0200
  • 13. Tasty Ruby Manipulation de dates Closures
  • 14. > ["one", "two", "three"].map { |word| word.upcase } => ["ONE", "TWO", "THREE"] > [1, 2, 3, 4, 5].find_all { |item| item > 3 } => [4, 5]
  • 16. Un framework fait pour le web Controlleur Templating Routing REST ActiveRecord
  • 17. fichier app/controllers/books_controller.rb class BooksController < ApplicationController def index @books = Book.all end end
  • 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
  • 21. fichier app/views/books/index.html.erb <h1>Listing Books</h1> <table> <tr> <th>Title</th> <th>Summary</th> <th></th> <th></th> <th></th> </tr> <% @books.each do |book| %> <tr> <td><%= book.title %></td> <td><%= book.content %></td> <td><%= link_to 'Show', book %></td> <td><%= link_to 'Edit', edit_book_path(book) %></td> <td><%= link_to 'Remove', book,:method => :delete %></td> </tr> <% end %> </table> <%= link_to 'New book', new_book_path %>
  • 22. fichier app/views/books/index.html.haml %h1 Listing Books %table %tr %th Title %th Summary %th %th %th - @books.each do |book| %tr %td= book.title %td= book.content %td= link_to 'Show', book %td= link_to 'Edit', edit_book_path(book) %td= link_to 'Remove', book,:method => :delete = link_to 'New book', new_book_path
  • 23. fichier app/views/books/index.html.haml %h1 Listing Books %table %tr %th Title %th Summary %th %th %th - @books.each do |book| %tr %td= book.title %td= book.content %td= link_to 'Show', book %td= link_to 'Edit', edit_book_path(book) %td= link_to 'Remove', book,:method => :delete = link_to 'New book', new_book_path Haml takes your gross, ugly templates and replaces them with veritable Haiku. Haml is based on one primary principle : markup should be beautiful.
  • 24. {markup haiku} {style with attitude} http://haml-lang.com/ http://sass-lang.com/
  • 25. Un framework fait pour le web Controlleur Templating Routing REST ActiveRecord
  • 26. POST /books/create GET /books/show/1 POST /books/update/1 POST /books/destroy/1
  • 27. POST /books/ GET /books/1 PUT /books/1 DELETE /books/1
  • 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"})
  • 42. Un framework fait pour l’agile Testing Déploiement
  • 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
  • 47. require 'test/unit' require 'mocha' Mocha require 'fakeweb' class MiscExampleTest < Test::Unit::TestCase end tmcnem
  • 48. require 'test/unit' require 'mocha' Mocha require 'fakeweb' class MiscExampleTest < Test::Unit::TestCase def test_with_basic_mocha_stubbing product = Product.new product.stubs(:prices).returns([1000, 2000]) assert_equal [1000, 2000], product.prices end end tmcnem
  • 49. require 'test/unit' require 'mocha' Mocha require 'fakeweb' class MiscExampleTest < Test::Unit::TestCase def test_with_basic_mocha_stubbing product = Product.new product.stubs(:prices).returns([1000, 2000]) assert_equal [1000, 2000], product.prices end def test_with_mocha_object_stubbing prices = [stub(:pence => 1000), stub(:pence => 2000)] product = Product.new product.stubs(:prices).returns(prices) assert_equal [1000, 2000], product.prices.collect {|p| p.pence} end end tmcnem
  • 51. fichier test/factories.rb Factory.sequence :email do |n| "person#{n}@octo.com" end Factory.define :user do |u| u.first_name 'Robert' u.last_name 'Redford' u.email { Factory.next(:email) } end github.com/thoughtbot/factory_girl
  • 52. fichier test/factories.rb Factory.sequence :email do |n| "person#{n}@octo.com" end Factory.define :user do |u| u.first_name 'Robert' u.last_name 'Redford' u.email { Factory.next(:email) } end fichier test/unit/a_test.rb u = Factory :user assert_equal "Robert", user.first_name assert_equal "Redford", user.last_name u = Factory :user,:email => "rob@gmail.com" assert_equal "rob@gmail.com", u.email github.com/thoughtbot/factory_girl
  • 53. fichier test/factories.rb Factory.sequence :email do |n| "person#{n}@octo.com" end Factory.define :user do |u| u.first_name 'Robert' u.last_name 'Redford' u.email { Factory.next(:email) } end fichier test/unit/a_test.rb u = Factory :user assert_equal "Robert", user.first_name assert_equal "Redford", user.last_name u = Factory :user,:email => "rob@gmail.com" assert_equal "rob@gmail.com", u.email Fixture replacement for focused and readable tests github.com/thoughtbot/factory_girl
  • 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
  • 57. Un framework fait pour l’agile Testing Déploiement
  • 58.
  • 59. AfterTheWeekend Rassembler, Enrichir, Imprimer vos photos d’évènements aftertheweekend.fr @afterwee 3ème prix du Startup Weekend !
  • 60.

Notas do Editor