lecture 8 software as a service ( saas ) topics saassaas readings: saas book ch 2 february 17 2014...

50
Lecture 8 Software as a Service (SaaS ) Topics Topics SaaS SaaS Readings: Readings: SaaS book Ch SaaS book Ch 2 2 February 17 2014 CSCE 740 Software Engineering

Upload: jodie-wilkinson

Post on 29-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

Lecture 8Software as a Service (SaaS )

Lecture 8Software as a Service (SaaS )

Topics Topics

• SaaSSaaS

Readings: Readings: SaaS book Ch 2SaaS book Ch 2

February 17 2014

CSCE 740 Software Engineering

Page 2: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 2 – CSCE 740 Spring 2014

Last TimeLast Time Chapter 16 Software Reuse

New SaaS New SaaS

edX/169 site: Courseware: Lectures for each week; HW Discussion: Blog for each week Wiki: YouTube videos Tutorials and Resources; Syllabus: textbook & VM; Progress

http://vimeo.com/saasbook/videos

SaaS SoftwareSaaS Software

Ruby; Rails; Cucumber; Capybara; Rspec; :Ruby; Rails; Cucumber; Capybara; Rspec; :

Next Time: Next Time:

xx

Page 3: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 3 – CSCE 740 Spring 2014

CS 169.1 Lecture Schedule EdXCS 169.1 Lecture Schedule EdX

Page 4: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 4 – CSCE 740 Spring 2014

HW 2 – Rails – Rotten Potatoes HW 2 – Rails – Rotten Potatoes

1.1. git clone git://github.com/saasbook/hw2_rottenpotatoes.gitgit clone git://github.com/saasbook/hw2_rottenpotatoes.git

2.2. bundle install --without productionbundle install --without production

3.3. rake db:migraterake db:migrate

4.4. rake db:seedrake db:seed

5.5. rails serverrails server

6.6. Create a free Heroku.com (http://www.heroku.com) accountCreate a free Heroku.com (http://www.heroku.com) account• Name rottenpotatoes will be taken already

7.7. heroku run rake db:migrateheroku run rake db:migrate

8.8. heroku run rake db:seedheroku run rake db:seed

Page 5: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 5 – CSCE 740 Spring 2014

Software as a Service SaaSSoftware as a Service SaaS

client-serverclient-server

three-tier architecturethree-tier architecture

Design PatternsDesign Patterns

Model View ControllerModel View Controller

Model deals with app’s resources:e.g. users, movies,Model deals with app’s resources:e.g. users, movies,……

Controllers map broweser actions to application Controllers map broweser actions to application codecode

SaaS book – Chapter 2

Page 6: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 6 – CSCE 740 Spring 2014

Ruby with RailsRuby with Rails

Rails uses Active Record pattern for modelsRails uses Active Record pattern for models

because it maps well to relational databasesbecause it maps well to relational databases

For views Rails uses the Template View patternFor views Rails uses the Template View pattern

For Controllers Rails follows the Represntational State For Controllers Rails follows the Represntational State transfer (REST) principletransfer (REST) principle

each controller action describes a single self-each controller action describes a single self-contained operation on one of the application’s contained operation on one of the application’s resourcesresources

Modern SaaS frameworks such as rails capture Modern SaaS frameworks such as rails capture developer experience by supporting SaaS design developer experience by supporting SaaS design patternspatterns

SaaS book – Chapter 2

Page 7: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 7 – CSCE 740 Spring 2014

RailsRails

Rails is a web application development framework in RubyRails is a web application development framework in Ruby

The Rails philosophy includes several guiding principles:The Rails philosophy includes several guiding principles:

DRY – “Don’t Repeat Yourself” – suggests that writing the DRY – “Don’t Repeat Yourself” – suggests that writing the same code over and over again is a bad thing.same code over and over again is a bad thing.

Convention Over Configuration – means that Rails makes Convention Over Configuration – means that Rails makes assumptions about what you want to do and how you’re assumptions about what you want to do and how you’re going to do it, rather than requiring you to specify every going to do it, rather than requiring you to specify every little thing through endless configuration files.little thing through endless configuration files.

REST (Representational State Transfer) is the best pattern REST (Representational State Transfer) is the best pattern for web applicationsfor web applications

http://guides.rubyonrails.org/getting_started.html

Page 8: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 8 – CSCE 740 Spring 2014

2.1 100,000 Feet: Client-Server Architecture2.1 100,000 Feet: Client-Server Architecture

to Appendix A and get this book’s “bookware” running to Appendix A and get this book’s “bookware” running on your own computer or in the cloud.on your own computer or in the cloud.

Screencast 2.1.1 - shows how to deploy and login to Screencast 2.1.1 - shows how to deploy and login to your Virtual Machine and try an interaction with the your Virtual Machine and try an interaction with the simple educational app RottenPotatoes,simple educational app RottenPotatoes,

SaaS book – Chapter 2

Page 9: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 9 – CSCE 740 Spring 2014SaaS book – Chapter 2

Page 10: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 10 – CSCE 740 Spring 2014

Design PatternsDesign Patterns

““design pattern—design pattern—

a reusable structure, behavior, strategy, or technique a reusable structure, behavior, strategy, or technique

that captures a proven solution to a collection of that captures a proven solution to a collection of similar problems similar problems

by separating the things that change from those that by separating the things that change from those that stay the same”stay the same”

Examples:Examples: client-server model-view-controller

Design Patterns book – GoF (Gang Of Four)Design Patterns book – GoF (Gang Of Four)

SaaS book – Chapter 2

Page 11: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 11 – CSCE 740 Spring 2014

SaaS SummarySaaS Summary ““SaaS Web apps are examples of the SaaS Web apps are examples of the client-server client-server

architectural patternarchitectural pattern, , client sending requests to the server on the user’s behalf, and the server software is specialized for handling large

volumes of such requests.

Because Web apps use open standards that anyone Because Web apps use open standards that anyone can implement royalty-free, the Web browser has can implement royalty-free, the Web browser has become the “become the “universal clientuniversal client.” .”

An alternative to client-server is An alternative to client-server is peer-to-peerpeer-to-peer, in , in which all entities act as both clients and servers. which all entities act as both clients and servers. While arguably more flexible, this architecture makes While arguably more flexible, this architecture makes it difficult to specialize the software to do either job it difficult to specialize the software to do either job really well”really well”

SaaS book – Chapter 2

Page 12: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 12 – CSCE 740 Spring 2014

2.2 50,000 Feet: Communication—HTTP and URIs2.2 50,000 Feet: Communication—HTTP and URIs

Network protocol – “set of communication rules on Network protocol – “set of communication rules on which agents participating in a network agree”which agents participating in a network agree”

HTTP –HTTP –

TCP/IP –TCP/IP –

IP address – 129.252.11.170IP address – 129.252.11.170

Domain Name System (DNS) protocol on top of Domain Name System (DNS) protocol on top of TCP/IPTCP/IP

hostname to IP address mappinghostname to IP address mapping www.cse.sc.edu 129.252.???.???

local hostlocal host

SaaS book – Chapter 2

Page 13: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 13 – CSCE 740 Spring 2014

Port NumbersPort Numbers

Port numbers from 1 to 65535 to distinguish servers at Port numbers from 1 to 65535 to distinguish servers at the same IP address.the same IP address.

80 webserver80 webserver

22 ssh22 ssh

443 https443 https

The IANA. The Internet Assigned Numbers Authority The IANA. The Internet Assigned Numbers Authority assigns official default port numbers for various assigns official default port numbers for various protocols and manages the top-level or “root” zone protocols and manages the top-level or “root” zone of DNS.of DNS.

. .

SaaS book – Chapter 2

Page 14: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 14 – CSCE 740 Spring 2014

URIs versus URLsURIs versus URLs

A Uniform Resource Identifier (URI) names a resource A Uniform Resource Identifier (URI) names a resource available on the Internet. The interpretation of the available on the Internet. The interpretation of the resource name varies from application to resource name varies from application to application.application.

SaaS book – Chapter 2

Page 15: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 15 – CSCE 740 Spring 2014

HTTP cookiesHTTP cookies

HTTP cookies associate a particular user’s browser HTTP cookies associate a particular user’s browser with information held at the server corresponding to with information held at the server corresponding to that user’s session that user’s session

it is the browser’s responsibility, not HTTP’s or the it is the browser’s responsibility, not HTTP’s or the SaaS app’s, to make sure the right cookies are SaaS app’s, to make sure the right cookies are included with each HTTP request. included with each HTTP request.

Stateless protocols therefore simplify server design Stateless protocols therefore simplify server design at the expense of application design, at the expense of application design,

but happily, successful frameworks such as Rails but happily, successful frameworks such as Rails shield you from much of this complexity.shield you from much of this complexity.

SaaS book – Chapter 2

Page 16: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 16 – CSCE 740 Spring 2014

2.3 10,000 Feet: Representation—HTML and CSS2.3 10,000 Feet: Representation—HTML and CSS

Screencast 2.3.1: HTML IntroductionScreencast 2.3.1: HTML Introduction

Screencast 2.3.2: Inspecting the ID and Class attributes Screencast 2.3.2: Inspecting the ID and Class attributes CSS uses selector notationsCSS uses selector notations

Screencast 2.3.3: Introduction to CSSScreencast 2.3.3: Introduction to CSS

SaaS book – Chapter 2

Page 17: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 17 – CSCE 740 Spring 2014

The MVC ArchitectureThe MVC Architecture

““Model–View–Controller (MVC) is an architecture that Model–View–Controller (MVC) is an architecture that separates the representation of information from the separates the representation of information from the user's interaction with it”user's interaction with it”

Models – represent the dataModels – represent the data

Views – the User InterfaceViews – the User Interface

Controllers – the “glue” between models and viewsControllers – the “glue” between models and views

http://en.wikipedia.org/wiki/Model-view-controller

Page 18: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 18 – CSCE 740 Spring 2014

The Components of RailsThe Components of RailsAction Pack Action Pack

Action Controller - manages the controllers in Rails apps Action Dispatch - handles routing of web requests Action View - manages the view in Rails apps

Action Mailer - a framework for building e-mail servicesAction Mailer - a framework for building e-mail services

Active Model - interface between the Action Pack gem Active Model - interface between the Action Pack gem services and Object Relationship Mapping gems such services and Object Relationship Mapping gems such as Active Recordas Active Record

Active Record - base for the models in a Rails AppsActive Record - base for the models in a Rails Apps

Active Resource - framework for connection between Active Resource - framework for connection between business objects and web servicesbusiness objects and web services

Active SupportActive Support

RailtiesRailtieshttp://guides.rubyonrails.org/getting_started.html

Page 19: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 19 – CSCE 740 Spring 2014

Representational State Transfer (REST)Representational State Transfer (REST)

Roy Fielding’s doctoral thesis, Roy Fielding’s doctoral thesis, Architectural Styles and the Design of Network-based Software Architectures

““REST in terms of Rails boils down to two main REST in terms of Rails boils down to two main principles:principles:

1.1. Using resource identifiers such as URLs to represent Using resource identifiers such as URLs to represent resources.resources.

2.2. Transferring representations of the state of that Transferring representations of the state of that resource between system components”resource between system components”

http://guides.rubyonrails.org/getting_started.html

Page 20: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 20 – CSCE 740 Spring 2014

Creating a New Rails ProjectCreating a New Rails Project

# gem install rails# gem install rails

$ rails –version$ rails –version

$ rails new blog$ rails new blog

$ rails new –h$ rails new –h

Usage:Usage:

rails new APP_PATH [options]rails new APP_PATH [options]

……

$ cd blog$ cd blog

http://guides.rubyonrails.org/getting_started.html

Page 21: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 21 – CSCE 740 Spring 2014

Rails Application DirectoryRails Application Directory

File/Folder Purpose

app/ Contains the controllers, models, views and assets for your appl

config/ Configure your application’s runtime rules, routes, database, and

config.ru Rack configuration for Rack based servers used to start the appl

db/ Contains your current database schema, and db migrations.

doc/ In-depth documentation for your application.

GemfileGemfile.lock

These files allow you to specify what gem dependencies are needed for your Rails application.

lib/ Extended modules for your application.

log/ Application log files.

public/ Contains the static files and compiled assets.

http://guides.rubyonrails.org/getting_started.html

Page 22: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 22 – CSCE 740 Spring 2014

Rails Application Directory (continued)Rails Application Directory (continued)

README.rdocThis is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.

script/Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.

test/Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications

tmp/ Temporary files

vendor/

A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you optionally install it into your project) and plugins containing additional prepackaged functionality.

Rakefile

This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.

http://guides.rubyonrails.org/getting_started.html

Page 23: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 23 – CSCE 740 Spring 2014

Rails Application Directory: appRails Application Directory: app

This is your application, it contains:This is your application, it contains:

assets - assets - images javascripts stylesheetsimages javascripts stylesheets

controllers - controllers - • application_controller.rb • movies_controller.rb

helpers helpers application_helper.rb movies_helper.rbapplication_helper.rb movies_helper.rb

mailers mailers

models - models - movie.rbmovie.rb

Views – Views – • layouts: application.html.haml• movies: edit.html.haml index.html.haml new.html.haml

show.html.haml

Page 24: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 24 – CSCE 740 Spring 2014

HAML – a lightweight Markup LanguageHAML – a lightweight Markup Language

““used to describe the used to describe the XHTML of any of any web document without the use of traditional inline coding”without the use of traditional inline coding”

““Haml functions as a replacement for inline page Haml functions as a replacement for inline page templating systems such as templating systems such as PHP, , RHTML, and , and ASP””

http://en.wikipedia.org/wiki/Haml

Page 25: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 25 – CSCE 740 Spring 2014

YAMLYAML

YAML (rhymes with YAML (rhymes with camelcamel) is a ) is a human-readable data serialization format format

YAMLYAML is a is a recursive acronym for for

• "YAML Ain't "YAML Ain't Markup Language” ”

• emphacizing data-orientation over document mark-upemphacizing data-orientation over document mark-up

http://www.yaml.org/start.htmlhttp://en.wikipedia.org/wiki/YAML

--- receipt: Oz-Ware Purchase Invoice date: 2007-08-06 customer:

given: Dorothy family: Gale

items: - part_no: A4786

descrip: Water Bucket (Filled) price: 1.47 quantity: 4

- part_no: E1628 descrip: High Heeled "Ruby" Slippers size: 8 price: 100.27 quantity: 1

Page 26: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 26 – CSCE 740 Spring 2014

Configuring a DatabaseConfiguring a Database

EnvironmentsEnvironments

• DevelopmentDevelopment

• Test - automated testsTest - automated tests

• Production Production

config/database.ymlconfig/database.yml development:   adapter: sqlite3   database: db/development.sqlite3   pool: 5   timeout: 5000

http://guides.rubyonrails.org/getting_started.html

Page 27: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 27 – CSCE 740 Spring 2014

Creating the DatabaseCreating the Database

rake db:create rake db:create // Rake is a general-purpose command-runner// Rake is a general-purpose command-runner

rake –Trake –T

rake about # List versions of all Rails frameworks and the env...rake about # List versions of all Rails frameworks and the env...

rake assets:clean # Remove compiled assetsrake assets:clean # Remove compiled assets

rake assets:precompile # Compile all the assets named in config.assets.pre...rake assets:precompile # Compile all the assets named in config.assets.pre...

rake cucumber # cucumber rake task not available (cucumber not in...rake cucumber # cucumber rake task not available (cucumber not in...

rake db:create # Create the database from config/database.yml for ...rake db:create # Create the database from config/database.yml for ...

rake db:drop # Drops the database for the current Rails.env (use...rake db:drop # Drops the database for the current Rails.env (use...

rake db:fixtures:load # Load fixtures into the current environment's data...rake db:fixtures:load # Load fixtures into the current environment's data...

rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE...rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE...

rake db:migrate:status # Display status of migrationsrake db:migrate:status # Display status of migrations

……

http://guides.rubyonrails.org/getting_started.html

Page 28: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 28 – CSCE 740 Spring 2014

Starting up the Web ServerStarting up the Web Server

$rails server //starts instance of the WEBrick web server$rails server //starts instance of the WEBrick web server

Set browser to Set browser to http://localhost:3000 “Welcome Aboard page”“Welcome Aboard page”

http://guides.rubyonrails.org/getting_started.html

Page 29: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 29 – CSCE 740 Spring 2014

rails generaterails generate

rails generate controller home indexrails generate controller home index

rails generaterails generate• Usage: rails generate GENERATOR [args] [options]

• General options:• -h, [--help] # Print generator's options and usage• -p, [--pretend] # Run but do not make any changes• -f, [--force] # Overwrite files that already exist• …

Page 30: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 30 – CSCE 740 Spring 2014

Setting the Application Home PageSetting the Application Home Page

Edit in text editorEdit in text editor

<h1>Hello, Rails!</h1><h1>Hello, Rails!</h1>

$ rm public/index.html$ rm public/index.html

Open the file config/routes.rbOpen the file config/routes.rb Blog::Application.routes.draw do     #...   # You can have the root of your site routed with "root"   # just remember to delete public/index.html.   root :to => "home#index"

The root :to => "home#index" tells Rails to map the root The root :to => "home#index" tells Rails to map the root action to the home controller’s index action.action to the home controller’s index action.

http://guides.rubyonrails.org/getting_started.html

Page 31: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 31 – CSCE 740 Spring 2014

Getting Up and Running Quickly with ScaffoldingGetting Up and Running Quickly with ScaffoldingCreating a ResourceCreating a Resource

$ rails generate scaffold Post name:str title:str content:text$ rails generate scaffold Post name:str title:str content:text

http://guides.rubyonrails.org/getting_started.html

File Purpose

db/migrate/20100207214_create_posts.rb Migration to create the posts table in db

app/models/post.rb The Post model

test/unit/post_test.rb Unit testing harness for the posts model

test/fixtures/posts.yml Sample posts for use in testing

config/routes.rb Edited to include routing info for posts

app/controllers/posts_controller.rb The Posts controller

app/views/posts/index.html.erb A view to display an index of all posts

app/views/posts/edit.html.erb A view to edit an existing post

app/views/posts/show.html.erb A view to display a single post

Page 32: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 32 – CSCE 740 Spring 2014

What’s Next?What’s Next?

The The Ruby on Rails guides

The The Ruby on Rails Tutorial

The The Ruby on Rails mailing list

The The #rubyonrails channel on irc.freenode.net channel on irc.freenode.net

http://guides.rubyonrails.org/getting_started.html

Page 33: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 33 – CSCE 740 Spring 2014

Rails Summary – from SaasbookRails Summary – from Saasbook• Rails defines three environments—development, production and testRails defines three environments—development, production and test

—each with its own copy of the database. —each with its own copy of the database.

• A migration is a script describing a specific set of changes to the A migration is a script describing a specific set of changes to the database. As apps evolve and add features, migrations are added database. As apps evolve and add features, migrations are added

• Changing a database using a migration takes three steps: create the Changing a database using a migration takes three steps: create the migration, apply the migration to development database, and after migration, apply the migration to development database, and after testing apply the migration to production database. testing apply the migration to production database.

• The rails generate migration generator fills in the boilerplate for a new The rails generate migration generator fills in the boilerplate for a new migration, and the ActiveRecord::Migration class contains helpful migration, and the ActiveRecord::Migration class contains helpful methods for defining it. methods for defining it.

• rake db:migrate applies only those migrations not already applied to rake db:migrate applies only those migrations not already applied to the development database. The method for applying migrations to a the development database. The method for applying migrations to a production database depends on the deployment environment.production database depends on the deployment environment.

Patterson, David; Fox, Armando (2012-07-11). Engineering Long-Lasting Patterson, David; Fox, Armando (2012-07-11). Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta Software: An Agile Approach Using SaaS and Cloud Computing, Beta EditionEdition

Page 34: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 34 – CSCE 740 Spring 2014

Active Record SummaryActive Record Summary

• Active Record uses convention over configuration to infer Active Record uses convention over configuration to infer database table names from the names of model classes, and to database table names from the names of model classes, and to infer the names and types of the columns (attributes) infer the names and types of the columns (attributes) associated with a given kind of model. associated with a given kind of model.

• Basic Active Record support focuses on the CRUD actions: Basic Active Record support focuses on the CRUD actions: create, read, update, delete. create, read, update, delete.

• Model instances can be Created either by calling new followed Model instances can be Created either by calling new followed by save or by calling create, which combines the two. by save or by calling create, which combines the two.

• Every model instance saved in the database receives an ID Every model instance saved in the database receives an ID number unique within its table called the primary key, …number unique within its table called the primary key, …

• Patterson, David; Fox, Armando (2012-07-11). Engineering Patterson, David; Fox, Armando (2012-07-11). Engineering Long-Lasting Software: An Agile Approach Using SaaS and Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta EditionCloud Computing, Beta Edition

Page 35: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 35 – CSCE 740 Spring 2014

Summary: Haml Summary: Haml

• Haml allows you to intersperse HTML tags with Ruby Haml allows you to intersperse HTML tags with Ruby code for your views. The result of evaluating Ruby code for your views. The result of evaluating Ruby code can either be discarded or interpolated into the code can either be discarded or interpolated into the HTML page. HTML page.

• For conciseness, Haml relies on indentation to reveal For conciseness, Haml relies on indentation to reveal HTML element nesting. HTML element nesting.

• Convention over configuration is used to determine Convention over configuration is used to determine the file names for controllers and views the file names for controllers and views corresponding to a given model. If the RESTful route corresponding to a given model. If the RESTful route helpers are used, as in resources :movies, helpers are used, as in resources :movies, convention over configuration also maps RESTful convention over configuration also maps RESTful action names to controller action (method) names. action names to controller action (method) names.

Page 36: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 36 – CSCE 740 Spring 2014

HAML summary continuedHAML summary continued

• Rails provides various helper methods that take Rails provides various helper methods that take advantage of the RESTful route URIs, including advantage of the RESTful route URIs, including link_to for generating HTML links whose URIs refer link_to for generating HTML links whose URIs refer to RESTfulto RESTful

Patterson, David; Fox, Armando (2012-07-11). Patterson, David; Fox, Armando (2012-07-11). Engineering Long-Lasting Software: An Agile Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing, Beta Approach Using SaaS and Cloud Computing, Beta

Page 37: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 37 – CSCE 740 Spring 2014

Heroku - CloudHeroku - Cloud

Heroku is a cloud Heroku is a cloud platform as a service (PaaS) supporting several programming languages. supporting several programming languages.

Heroku, one of the first cloud platforms, has been in Heroku, one of the first cloud platforms, has been in development since June 2007 when it supported development since June 2007 when it supported Ruby Ruby

http://en.wikipedia.org/wiki/Heroku

Page 38: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 38 – CSCE 740 Spring 2014

Heroku ToolbeltHeroku Toolbelt

What is it?What is it?

Heroku client - CLI tool for creating and managing Heroku Heroku client - CLI tool for creating and managing Heroku appsapps

Foreman - an easy option for running your apps locallyForeman - an easy option for running your apps locally

Git - revision control and pushing to HerokuGit - revision control and pushing to Heroku

• Runs on your machine Runs on your machine $ heroku login $ heroku login Enter your Heroku credentials. Enter your Heroku credentials. Email: [email protected] Email: [email protected] Password: Password: Could not find an existing public key. Would you like to generate one? Could not find an existing public key. Would you like to generate one?

[Yn] Generating new SSH public key. [Yn] Generating new SSH public key. Uploading ssh public key /Users/adam/.ssh/id_rsa.pubUploading ssh public key /Users/adam/.ssh/id_rsa.pub

https://toolbelt.heroku.com/

Page 39: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 39 – CSCE 740 Spring 2014

Heroku Toolbelt continuedHeroku Toolbelt continued

You're now ready to create your first Heroku app:You're now ready to create your first Heroku app:

$ cd ~/myapp $ cd ~/myapp

$ heroku create $ heroku create

Creating stark-fog-398... done, stack is cedar Creating stark-fog-398... done, stack is cedar

http://stark-fog-398.herokuapp.com/ | http://stark-fog-398.herokuapp.com/ | [email protected]:stark-fog-398.git [email protected]:stark-fog-398.git

Git remote heroku added Git remote heroku added

Technical detailsTechnical details

The install script will add our repository and key to your apt sources The install script will add our repository and key to your apt sources and then have apt install the heroku and foreman packages from and then have apt install the heroku and foreman packages from it. The heroku command line client will be installed into it. The heroku command line client will be installed into /usr/local/heroku and /usr/local/heroku/bin will be added to your /usr/local/heroku and /usr/local/heroku/bin will be added to your PATH.PATH.

Page 40: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 40 – CSCE 740 Spring 2014

Heroku APIHeroku API

https://api-docs.heroku.com/https://api-docs.heroku.com/

Page 41: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 41 – CSCE 740 Spring 2014

References – Cucumber and RspecReferences – Cucumber and Rspec

• http://pragprog.com/book/hwcuc/the-cucumber-bookhttp://pragprog.com/book/hwcuc/the-cucumber-book• Code

• Download hwcuc-code.tgz• Copyrights apply to this source code. You may use the source

code in your own projects, however the source code may not be used to create training material, courses, books, articles, and the like. We make no guarantees that this source code is fit for any purpose.

• http://cukes.info/http://cukes.info/

• http://pragprog.com/book/achbd/the-rspec-bookhttp://pragprog.com/book/achbd/the-rspec-book• Code

• http://www.slideshare.nethttp://www.slideshare.net

Page 42: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 42 – CSCE 740 Spring 2014

Behavior Driven Design in Cucumber Behavior Driven Design in Cucumber

1.1. Describe behaviour in plain textDescribe behaviour in plain text

2.2. Write a step definition in RubyWrite a step definition in Ruby

3.3. Run and watch it failRun and watch it fail

4.4. Write code to make the step passWrite code to make the step pass

5.5. Run again and see the step passRun again and see the step pass

6.6. Repeat 2-5 until green like a cukeRepeat 2-5 until green like a cuke

7.7. Repeat 1-6 until the money runs outRepeat 1-6 until the money runs out

http://cukes.info/

Page 43: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 43 – CSCE 740 Spring 2014

Cucumber Ex.: 1 Describe BehaviorCucumber Ex.: 1 Describe Behavior

Create feature and ScenariosCreate feature and Scenarios

http://cukes.info/

Page 44: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 44 – CSCE 740 Spring 2014

Cucumber Ex: 2 Write step definitionCucumber Ex: 2 Write step definition

http://cukes.info/

Page 45: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 45 – CSCE 740 Spring 2014

Cucumber Ex.: 3 Run/watch it failCucumber Ex.: 3 Run/watch it fail

GivenGiven

WhenWhen

ThenThen

http://cukes.info/

Page 46: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 46 – CSCE 740 Spring 2014

Rails Tutorial for Devise with RSpec and CucumberRails Tutorial for Devise with RSpec and Cucumberby Daniel Kehoe by Daniel Kehoe Last updated 1 September 2012Last updated 1 September 2012

Ruby on Rails tutorial showing how to create a Rails 3.2 application Ruby on Rails tutorial showing how to create a Rails 3.2 application using Devise with RSpec and Cucumber.using Devise with RSpec and Cucumber.

Devise gives you ready-made authentication and user management.Devise gives you ready-made authentication and user management.

RSpec is a popular alternative to the Test::Unit testing framework.RSpec is a popular alternative to the Test::Unit testing framework.

Cucumber is used for Behaviour Driven Development.Cucumber is used for Behaviour Driven Development.

Here’s what you can do:Here’s what you can do:

learn as-you-go by following the steps in this tutorial to build a starter learn as-you-go by following the steps in this tutorial to build a starter appapp

clone the example code from the GitHub repo for a ready-to-use clone the example code from the GitHub repo for a ready-to-use starter appstarter app

generate a customized starter app with the Rails Composer toolgenerate a customized starter app with the Rails Composer tool

http://railsapps.github.com/tutorial-rails-devise-rspec-cucumber.html

Page 47: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 47 – CSCE 740 Spring 2014

Cucumber Ex.: 4 Write code to passCucumber Ex.: 4 Write code to pass

http://cukes.info/

Page 48: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 48 – CSCE 740 Spring 2014

Cucumber Ex.: 5 Run againCucumber Ex.: 5 Run again

http://cukes.info/

Page 49: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 49 – CSCE 740 Spring 2014

Cucumber Ex.: 6 Repeat 2-5 greenCucumber Ex.: 6 Repeat 2-5 green

http://cukes.info/

Page 50: Lecture 8 Software as a Service ( SaaS ) Topics SaaSSaaS Readings: SaaS book Ch 2 February 17 2014 CSCE 740 Software Engineering

– 50 – CSCE 740 Spring 2014

HW 3 : Behavior-Driven DesignHW 3 : Behavior-Driven Design

1.1. SetupSetupa. git clone [email protected]:YourGitHubAccount/hw3_rottenpotatoes.git

b. git commit

c. git tag hw3-part1b

d. git diff hw3-part1b

e. git push origin --tags

2. Create a declarative scenario step for adding movies

3. Happy paths for filtering movies

4. Happy paths for sorting movies by title and by release date

5. HW 3 Submission - features directory onlya. tar czf features.tar.gz features/