From f9d9ddcaa0365d8cda6e11ea3e5715222a0f702f Mon Sep 17 00:00:00 2001 From: pavelperkin Date: Fri, 4 Oct 2013 02:59:13 +0300 Subject: [PATCH 1/5] deploy --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 9a2ccae..baa3995 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,9 @@ 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 From b1c18b167a519dd28370689ae4eea7693623309c Mon Sep 17 00:00:00 2001 From: pavelperkin Date: Fri, 4 Oct 2013 03:00:14 +0300 Subject: [PATCH 2/5] deploy --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From e1cf9120c74261893a6a801282499d942ca3c98b Mon Sep 17 00:00:00 2001 From: pavelperkin Date: Sun, 6 Oct 2013 00:19:09 +0300 Subject: [PATCH 3/5] Add menu to restaurant. Try Ajax --- Gemfile | 2 - Gemfile.lock | 12 ++++- app/assets/javascripts/menus.js.coffee | 3 ++ app/assets/stylesheets/menus.css.scss | 3 ++ app/controllers/menus_controller.rb | 55 +++++++++++++++++++++++ app/controllers/restaurants_controller.rb | 53 +++++----------------- app/helpers/menus_helper.rb | 2 + app/models/menu.rb | 4 ++ app/models/restaurant.rb | 1 + app/views/menus/_form.html.erb | 21 +++++++++ app/views/menus/_new.html.erb | 14 ++++++ app/views/menus/create.js.erb | 1 + app/views/menus/edit.html.erb | 6 +++ app/views/menus/index.html.erb | 23 ++++++++++ app/views/menus/show.html.erb | 10 +++++ app/views/restaurants/edit.html.erb | 7 ++- config/routes.rb | 2 +- db/migrate/20131005143814_create_menus.rb | 10 +++++ db/schema.rb | 9 +++- test/fixtures/menus.yml | 7 +++ test/functional/menus_controller_test.rb | 49 ++++++++++++++++++++ test/unit/helpers/menus_helper_test.rb | 4 ++ test/unit/menu_test.rb | 7 +++ 23 files changed, 257 insertions(+), 48 deletions(-) create mode 100644 app/assets/javascripts/menus.js.coffee create mode 100644 app/assets/stylesheets/menus.css.scss create mode 100644 app/controllers/menus_controller.rb create mode 100644 app/helpers/menus_helper.rb create mode 100644 app/models/menu.rb create mode 100644 app/views/menus/_form.html.erb create mode 100644 app/views/menus/_new.html.erb create mode 100644 app/views/menus/create.js.erb create mode 100644 app/views/menus/edit.html.erb create mode 100644 app/views/menus/index.html.erb create mode 100644 app/views/menus/show.html.erb create mode 100644 db/migrate/20131005143814_create_menus.rb create mode 100644 test/fixtures/menus.yml create mode 100644 test/functional/menus_controller_test.rb create mode 100644 test/unit/helpers/menus_helper_test.rb create mode 100644 test/unit/menu_test.rb diff --git a/Gemfile b/Gemfile index baa3995..06cceeb 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,6 @@ gem 'rails', '3.2.13' # gem 'sqlite3' gem 'pg' - - # Gems used only for assets and not required # in production environments by default. group :assets do diff --git a/Gemfile.lock b/Gemfile.lock index 194b71b..91ec7ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,6 +30,7 @@ GEM multi_json (~> 1.0) arel (3.0.2) builder (3.0.4) + coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -49,10 +50,14 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.8.1) mime-types (1.25) multi_json (1.8.0) - pg (0.16.0) polyglot (0.3.3) + pry (0.9.12.2) + coderay (~> 1.0.5) + method_source (~> 0.8) + slop (~> 3.4) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -83,11 +88,13 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) + slop (3.4.5) sprockets (2.2.2) hike (~> 1.2) 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 +111,8 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 3.2.1) jquery-rails - pg + pry 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? %> +
+

<%= pluralize(@menu.errors.count, "error") %> prohibited this menu from being saved:

+ +
    + <% @menu.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :title %>
+ <%= f.text_field :title %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/menus/_new.html.erb b/app/views/menus/_new.html.erb new file mode 100644 index 0000000..13b9522 --- /dev/null +++ b/app/views/menus/_new.html.erb @@ -0,0 +1,14 @@ +

New menu

+<%= form_for(@menu, remote: true) do |f| %> +
+ <%= f.hidden_field :restaurant_id, :value => @restaurant.id%> + <%= f.label :title %>
+ <%= f.text_field :title %> +
+ <%= @restaurant.inspect %> +
+ <%= f.submit %> +
+<% end %> + +<%= link_to 'Back', menus_path %> diff --git a/app/views/menus/create.js.erb b/app/views/menus/create.js.erb new file mode 100644 index 0000000..b6fb82e --- /dev/null +++ b/app/views/menus/create.js.erb @@ -0,0 +1 @@ +alert('2'); \ No newline at end of file diff --git a/app/views/menus/edit.html.erb b/app/views/menus/edit.html.erb new file mode 100644 index 0000000..e2655c2 --- /dev/null +++ b/app/views/menus/edit.html.erb @@ -0,0 +1,6 @@ +

Editing menu

+ +<%= render 'form' %> + +<%= link_to 'Show', @menu %> | +<%= link_to 'Back', menus_path %> diff --git a/app/views/menus/index.html.erb b/app/views/menus/index.html.erb new file mode 100644 index 0000000..78af3b8 --- /dev/null +++ b/app/views/menus/index.html.erb @@ -0,0 +1,23 @@ +

Listing menus

+ + + + + + + + + +<% @menus.each do |menu| %> + + + + + + +<% end %> +
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?' } %>
+ +
+ +<%= link_to 'New Menu', new_menu_path %> diff --git a/app/views/menus/show.html.erb b/app/views/menus/show.html.erb new file mode 100644 index 0000000..063755d --- /dev/null +++ b/app/views/menus/show.html.erb @@ -0,0 +1,10 @@ +

<%= 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 From 774e1d14279c6284ff066ce9eb55411c94678b42 Mon Sep 17 00:00:00 2001 From: pavelperkin Date: Sun, 6 Oct 2013 00:19:52 +0300 Subject: [PATCH 4/5] deploy --- Gemfile.lock | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 91ec7ee..194b71b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,7 +30,6 @@ GEM multi_json (~> 1.0) arel (3.0.2) builder (3.0.4) - coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -50,14 +49,10 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - method_source (0.8.1) mime-types (1.25) multi_json (1.8.0) + pg (0.16.0) polyglot (0.3.3) - pry (0.9.12.2) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.4) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -88,13 +83,11 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - slop (3.4.5) sprockets (2.2.2) hike (~> 1.2) 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) @@ -111,8 +104,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 3.2.1) jquery-rails - pry + pg rails (= 3.2.13) sass-rails (~> 3.2.3) - sqlite3 uglifier (>= 1.0.3) From 172c1fbc979f7717bba7b6b9cae204ea85c2d324 Mon Sep 17 00:00:00 2001 From: pavelperkin Date: Thu, 4 Feb 2016 22:18:08 +0200 Subject: [PATCH 5/5] Create .cimon.yml --- .cimon.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .cimon.yml 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