diff --git a/.cimon.yml b/.cimon.yml new file mode 100644 index 0000000..42d2381 --- /dev/null +++ b/.cimon.yml @@ -0,0 +1,25 @@ +services: + rails: + from: ruby:2.1.2 + cache: + - /bundle + build: + - apt-get update + - apt-get install -y libqt4-dev pkg-config + - apt-get install -y nodejs postgresql-client sqlite3 + - apt-get install -y curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev libxml2-dev libxslt-dev + - gem install bundler + postgres: + from: postgres + +test: + prepare: + - bundle install --path /bundle + - bin/rake db:create + service: rails + folder: /app + cmd: "echo '%.......................%'" + env: + - RAILS_ENV=test + - RACK_ENV=test + - DATABASE_URL=postgres://postgres:mysecretpassword@127.0.0.1:5432/db diff --git a/Gemfile b/Gemfile index 9a2ccae..06cceeb 100644 --- a/Gemfile +++ b/Gemfile @@ -5,8 +5,8 @@ gem 'rails', '3.2.13' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' -gem 'sqlite3' - +# gem 'sqlite3' +gem 'pg' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 0cd9a79..194b71b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,7 @@ GEM treetop (~> 1.4.8) mime-types (1.25) multi_json (1.8.0) + pg (0.16.0) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -87,7 +88,6 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.8) thor (0.18.1) tilt (1.4.1) treetop (1.4.15) @@ -104,7 +104,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 3.2.1) jquery-rails + pg rails (= 3.2.13) sass-rails (~> 3.2.3) - sqlite3 uglifier (>= 1.0.3) diff --git a/app/assets/javascripts/menus.js.coffee b/app/assets/javascripts/menus.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/menus.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/menus.css.scss b/app/assets/stylesheets/menus.css.scss new file mode 100644 index 0000000..ee0d72b --- /dev/null +++ b/app/assets/stylesheets/menus.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Menus controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/menus_controller.rb b/app/controllers/menus_controller.rb new file mode 100644 index 0000000..ec6d099 --- /dev/null +++ b/app/controllers/menus_controller.rb @@ -0,0 +1,55 @@ +class MenusController < ApplicationController + respond_to :html, :js + before_filter :find_menu, only: [:show, :edit, :update, :destroy] + + def show + respond_to do |format| + format.html # show.html.erb + format.json { render json: @menu } + end + end + + def new + @menu = Menu.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @menu } + end + end + + def edit + end + + def create + @menu = Menu.create(params[:menu]) + end + + def update + + respond_to do |format| + if @menu.update_attributes(params[:menu]) + format.html { redirect_to @menu, notice: 'Menu was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @menu.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @menu.destroy + + respond_to do |format| + format.html { redirect_to menus_url } + format.json { head :no_content } + end + end + + private + + def find_menu + @menu = Menu.find(params[:id]) + end +end diff --git a/app/controllers/restaurants_controller.rb b/app/controllers/restaurants_controller.rb index 060964f..ba2006c 100644 --- a/app/controllers/restaurants_controller.rb +++ b/app/controllers/restaurants_controller.rb @@ -1,83 +1,54 @@ class RestaurantsController < ApplicationController - # GET /restaurants - # GET /restaurants.json + + before_filter :find_restaurant, only: [:show, :edit, :update, :destroy] + def index @restaurants = Restaurant.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @restaurants } - end end - # GET /restaurants/1 - # GET /restaurants/1.json def show - @restaurant = Restaurant.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @restaurant } - end + @menus = @restaurant.menus end - # GET /restaurants/new - # GET /restaurants/new.json def new @restaurant = Restaurant.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @restaurant } - end end - # GET /restaurants/1/edit def edit - @restaurant = Restaurant.find(params[:id]) + @menu = @restaurant.menus.new end - # POST /restaurants - # POST /restaurants.json def create @restaurant = Restaurant.new(params[:restaurant]) - respond_to do |format| if @restaurant.save format.html { redirect_to @restaurant, notice: 'Restaurant was successfully created.' } - format.json { render json: @restaurant, status: :created, location: @restaurant } else format.html { render action: "new" } - format.json { render json: @restaurant.errors, status: :unprocessable_entity } end end end - # PUT /restaurants/1 - # PUT /restaurants/1.json - def update - @restaurant = Restaurant.find(params[:id]) - + def update respond_to do |format| if @restaurant.update_attributes(params[:restaurant]) format.html { redirect_to @restaurant, notice: 'Restaurant was successfully updated.' } - format.json { head :no_content } else format.html { render action: "edit" } - format.json { render json: @restaurant.errors, status: :unprocessable_entity } end end end - # DELETE /restaurants/1 - # DELETE /restaurants/1.json def destroy - @restaurant = Restaurant.find(params[:id]) @restaurant.destroy - respond_to do |format| format.html { redirect_to restaurants_url } - format.json { head :no_content } end end + + private + + def find_restaurant + @restaurant = Restaurant.find(params[:id]) + end end diff --git a/app/helpers/menus_helper.rb b/app/helpers/menus_helper.rb new file mode 100644 index 0000000..2a9d3f5 --- /dev/null +++ b/app/helpers/menus_helper.rb @@ -0,0 +1,2 @@ +module MenusHelper +end diff --git a/app/models/menu.rb b/app/models/menu.rb new file mode 100644 index 0000000..dba3710 --- /dev/null +++ b/app/models/menu.rb @@ -0,0 +1,4 @@ +class Menu < ActiveRecord::Base + attr_accessible :title, :restaurant_id + belongs_to :restaurant +end diff --git a/app/models/restaurant.rb b/app/models/restaurant.rb index 27e4119..927cf3c 100644 --- a/app/models/restaurant.rb +++ b/app/models/restaurant.rb @@ -1,3 +1,4 @@ class Restaurant < ActiveRecord::Base attr_accessible :building, :city, :description, :name, :phone, :street, :zip + has_many :menus end diff --git a/app/views/menus/_form.html.erb b/app/views/menus/_form.html.erb new file mode 100644 index 0000000..4f013cf --- /dev/null +++ b/app/views/menus/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@menu) do |f| %> + <% if @menu.errors.any? %> +
| Title | ++ | + | + |
|---|---|---|---|
| <%= menu.title %> | +<%= link_to 'Show', menu %> | +<%= link_to 'Edit', edit_menu_path(menu) %> | +<%= link_to 'Destroy', menu, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Title: + <%= @menu.title %> +
+ + +<%= link_to 'Edit', edit_menu_path(@menu) %> | +<%= link_to 'Back', menus_path %> diff --git a/app/views/restaurants/edit.html.erb b/app/views/restaurants/edit.html.erb index 3990e8f..917a090 100644 --- a/app/views/restaurants/edit.html.erb +++ b/app/views/restaurants/edit.html.erb @@ -3,4 +3,9 @@ <%= render 'form' %> <%= link_to 'Show', @restaurant %> | -<%= link_to 'Back', restaurants_path %> +<%= link_to 'Back', restaurants_path %> | ++<%= @restaurant.menus.count %> +
+ +<%= render 'menus/new' %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9cdbabf..cc3e48b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Lunch::Application.routes.draw do + resources :menus resources :restaurants - root to: "restaurants#index" diff --git a/db/migrate/20131005143814_create_menus.rb b/db/migrate/20131005143814_create_menus.rb new file mode 100644 index 0000000..b4db09d --- /dev/null +++ b/db/migrate/20131005143814_create_menus.rb @@ -0,0 +1,10 @@ +class CreateMenus < ActiveRecord::Migration + def change + create_table :menus do |t| + t.string :title + t.integer :restaurant_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5be37a0..0971d83 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131003234938) do +ActiveRecord::Schema.define(:version => 20131005143814) do + + create_table "menus", :force => true do |t| + t.string "title" + t.integer "restaurant_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end create_table "restaurants", :force => true do |t| t.string "name" diff --git a/test/fixtures/menus.yml b/test/fixtures/menus.yml new file mode 100644 index 0000000..1f0362f --- /dev/null +++ b/test/fixtures/menus.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + title: MyString + +two: + title: MyString diff --git a/test/functional/menus_controller_test.rb b/test/functional/menus_controller_test.rb new file mode 100644 index 0000000..babc3c4 --- /dev/null +++ b/test/functional/menus_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MenusControllerTest < ActionController::TestCase + setup do + @menu = menus(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:menus) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create menu" do + assert_difference('Menu.count') do + post :create, menu: { title: @menu.title } + end + + assert_redirected_to menu_path(assigns(:menu)) + end + + test "should show menu" do + get :show, id: @menu + assert_response :success + end + + test "should get edit" do + get :edit, id: @menu + assert_response :success + end + + test "should update menu" do + put :update, id: @menu, menu: { title: @menu.title } + assert_redirected_to menu_path(assigns(:menu)) + end + + test "should destroy menu" do + assert_difference('Menu.count', -1) do + delete :destroy, id: @menu + end + + assert_redirected_to menus_path + end +end diff --git a/test/unit/helpers/menus_helper_test.rb b/test/unit/helpers/menus_helper_test.rb new file mode 100644 index 0000000..e174484 --- /dev/null +++ b/test/unit/helpers/menus_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MenusHelperTest < ActionView::TestCase +end diff --git a/test/unit/menu_test.rb b/test/unit/menu_test.rb new file mode 100644 index 0000000..8f8cd93 --- /dev/null +++ b/test/unit/menu_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MenuTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end