Your SlideShare is downloading. ×
0
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Rails vu d'un Javaiste
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rails vu d'un Javaiste

1,271

Published on

Présentation de Ruby on Rails faite au Paris JUG le 12/10/2010

Présentation de Ruby on Rails faite au Paris JUG le 12/10/2010

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,271
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide


















































  • Transcript

    • 1. Ruby On Rails, vu d’un Javaiste Paris JUG, 12 octobre 2010 Christian Blavier cblavier@octo.com
    • 2. Sponsors Platiniums 2010
    • 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
    • 10. Manipulation de dates Closures
    • 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]
    • 15. Controlleur Templating Routing REST ActiveRecord
    • 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
    • 28. fichier config/routes.rb MyApp::Application.routes.draw do |map| resources :book end
    • 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. Run commande shell rails generate model book title:string description:string rake db:migrate
    • 37. 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
    • 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 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
    • 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 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"})
    • 40. Testing Déploiement
    • 41. Un framework fait pour l’agile Testing Déploiement
    • 42. Unit Testing Integration Testing Functional Testing
    • 43. 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
    • 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" 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
    • 45. 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
    • 46. require 'test/unit' require 'mocha' Mocha require 'fakeweb' class MiscExampleTest < Test::Unit::TestCase end tmcnem
    • 47. 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
    • 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 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
    • 49. github.com/thoughtbot/factory_girl
    • 50. 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
    • 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 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
    • 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 Fixture replacement for focused and readable tests github.com/thoughtbot/factory_girl
    • 53. github.com/jtrupiano/timecop
    • 54. 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
    • 55. 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
    • 56. Un framework fait pour l’agile Testing Déploiement
    • 57. AfterTheWeekend Rassembler, Enrichir, Imprimer vos photos d’évènements aftertheweekend.fr @afterwee 3ème prix du Startup Weekend !
    • 58. Yapluka !
    • 59. Yapluka !
    • 60. Yapluka !
    • 61. Yapluka !

    ×