From c397460cbe15b63f50fdbaa4876c3f716b32ce4b Mon Sep 17 00:00:00 2001 From: Srinivas Gumdelli Date: Wed, 27 May 2015 22:52:40 -0500 Subject: [PATCH] Adds resources --- Gemfile | 1 + Gemfile.lock | 3 + app/assets/javascripts/codes.coffee | 3 + app/assets/javascripts/conditions.coffee | 3 + app/assets/javascripts/ingredients.coffee | 3 + app/assets/stylesheets/codes.scss | 3 + app/assets/stylesheets/conditions.scss | 3 + app/assets/stylesheets/ingredients.scss | 3 + app/assets/stylesheets/scaffolds.scss | 69 ++++++++ app/controllers/codes_controller.rb | 58 ++++++ app/controllers/conditions_controller.rb | 58 ++++++ app/controllers/ingredients_controller.rb | 58 ++++++ app/helpers/codes_helper.rb | 2 + app/helpers/conditions_helper.rb | 2 + app/helpers/ingredients_helper.rb | 2 + app/models/code.rb | 2 + app/models/condition.rb | 2 + app/models/ingredient.rb | 2 + app/views/codes/_form.html.erb | 12 ++ app/views/codes/edit.html.erb | 6 + app/views/codes/index.html.erb | 29 +++ app/views/codes/new.html.erb | 5 + app/views/codes/show.html.erb | 14 ++ app/views/conditions/_form.html.erb | 12 ++ app/views/conditions/edit.html.erb | 6 + app/views/conditions/index.html.erb | 29 +++ app/views/conditions/new.html.erb | 5 + app/views/conditions/show.html.erb | 14 ++ app/views/ingredients/_form.html.erb | 12 ++ app/views/ingredients/edit.html.erb | 6 + app/views/ingredients/index.html.erb | 29 +++ app/views/ingredients/new.html.erb | 5 + app/views/ingredients/show.html.erb | 14 ++ config/database.yml | 23 +-- config/initializers/simple_form.rb | 166 ++++++++++++++++++ config/locales/simple_form.en.yml | 31 ++++ config/routes.rb | 6 + .../20150528033848_create_conditions.rb | 10 ++ .../20150528034145_create_ingredients.rb | 10 ++ db/migrate/20150528034336_create_codes.rb | 10 ++ db/schema.rb | 40 +++++ lib/templates/erb/scaffold/_form.html.erb | 13 ++ spec/controllers/codes_controller_spec.rb | 159 +++++++++++++++++ .../controllers/conditions_controller_spec.rb | 159 +++++++++++++++++ .../ingredients_controller_spec.rb | 159 +++++++++++++++++ spec/factories/codes.rb | 7 + spec/factories/conditions.rb | 7 + spec/factories/ingredients.rb | 7 + spec/helpers/codes_helper_spec.rb | 15 ++ spec/helpers/conditions_helper_spec.rb | 15 ++ spec/helpers/ingredients_helper_spec.rb | 15 ++ spec/models/code_spec.rb | 5 + spec/models/condition_spec.rb | 5 + spec/models/ingredient_spec.rb | 5 + spec/requests/codes_spec.rb | 10 ++ spec/requests/conditions_spec.rb | 10 ++ spec/requests/ingredients_spec.rb | 10 ++ spec/routing/codes_routing_spec.rb | 35 ++++ spec/routing/conditions_routing_spec.rb | 35 ++++ spec/routing/ingredients_routing_spec.rb | 35 ++++ spec/views/codes/edit.html.erb_spec.rb | 21 +++ spec/views/codes/index.html.erb_spec.rb | 22 +++ spec/views/codes/new.html.erb_spec.rb | 21 +++ spec/views/codes/show.html.erb_spec.rb | 16 ++ spec/views/conditions/edit.html.erb_spec.rb | 21 +++ spec/views/conditions/index.html.erb_spec.rb | 22 +++ spec/views/conditions/new.html.erb_spec.rb | 21 +++ spec/views/conditions/show.html.erb_spec.rb | 16 ++ spec/views/ingredients/edit.html.erb_spec.rb | 21 +++ spec/views/ingredients/index.html.erb_spec.rb | 22 +++ spec/views/ingredients/new.html.erb_spec.rb | 21 +++ spec/views/ingredients/show.html.erb_spec.rb | 16 ++ 72 files changed, 1701 insertions(+), 16 deletions(-) create mode 100644 app/assets/javascripts/codes.coffee create mode 100644 app/assets/javascripts/conditions.coffee create mode 100644 app/assets/javascripts/ingredients.coffee create mode 100644 app/assets/stylesheets/codes.scss create mode 100644 app/assets/stylesheets/conditions.scss create mode 100644 app/assets/stylesheets/ingredients.scss create mode 100644 app/assets/stylesheets/scaffolds.scss create mode 100644 app/controllers/codes_controller.rb create mode 100644 app/controllers/conditions_controller.rb create mode 100644 app/controllers/ingredients_controller.rb create mode 100644 app/helpers/codes_helper.rb create mode 100644 app/helpers/conditions_helper.rb create mode 100644 app/helpers/ingredients_helper.rb create mode 100644 app/models/code.rb create mode 100644 app/models/condition.rb create mode 100644 app/models/ingredient.rb create mode 100644 app/views/codes/_form.html.erb create mode 100644 app/views/codes/edit.html.erb create mode 100644 app/views/codes/index.html.erb create mode 100644 app/views/codes/new.html.erb create mode 100644 app/views/codes/show.html.erb create mode 100644 app/views/conditions/_form.html.erb create mode 100644 app/views/conditions/edit.html.erb create mode 100644 app/views/conditions/index.html.erb create mode 100644 app/views/conditions/new.html.erb create mode 100644 app/views/conditions/show.html.erb create mode 100644 app/views/ingredients/_form.html.erb create mode 100644 app/views/ingredients/edit.html.erb create mode 100644 app/views/ingredients/index.html.erb create mode 100644 app/views/ingredients/new.html.erb create mode 100644 app/views/ingredients/show.html.erb create mode 100644 config/initializers/simple_form.rb create mode 100644 config/locales/simple_form.en.yml create mode 100644 db/migrate/20150528033848_create_conditions.rb create mode 100644 db/migrate/20150528034145_create_ingredients.rb create mode 100644 db/migrate/20150528034336_create_codes.rb create mode 100644 db/schema.rb create mode 100644 lib/templates/erb/scaffold/_form.html.erb create mode 100644 spec/controllers/codes_controller_spec.rb create mode 100644 spec/controllers/conditions_controller_spec.rb create mode 100644 spec/controllers/ingredients_controller_spec.rb create mode 100644 spec/factories/codes.rb create mode 100644 spec/factories/conditions.rb create mode 100644 spec/factories/ingredients.rb create mode 100644 spec/helpers/codes_helper_spec.rb create mode 100644 spec/helpers/conditions_helper_spec.rb create mode 100644 spec/helpers/ingredients_helper_spec.rb create mode 100644 spec/models/code_spec.rb create mode 100644 spec/models/condition_spec.rb create mode 100644 spec/models/ingredient_spec.rb create mode 100644 spec/requests/codes_spec.rb create mode 100644 spec/requests/conditions_spec.rb create mode 100644 spec/requests/ingredients_spec.rb create mode 100644 spec/routing/codes_routing_spec.rb create mode 100644 spec/routing/conditions_routing_spec.rb create mode 100644 spec/routing/ingredients_routing_spec.rb create mode 100644 spec/views/codes/edit.html.erb_spec.rb create mode 100644 spec/views/codes/index.html.erb_spec.rb create mode 100644 spec/views/codes/new.html.erb_spec.rb create mode 100644 spec/views/codes/show.html.erb_spec.rb create mode 100644 spec/views/conditions/edit.html.erb_spec.rb create mode 100644 spec/views/conditions/index.html.erb_spec.rb create mode 100644 spec/views/conditions/new.html.erb_spec.rb create mode 100644 spec/views/conditions/show.html.erb_spec.rb create mode 100644 spec/views/ingredients/edit.html.erb_spec.rb create mode 100644 spec/views/ingredients/index.html.erb_spec.rb create mode 100644 spec/views/ingredients/new.html.erb_spec.rb create mode 100644 spec/views/ingredients/show.html.erb_spec.rb diff --git a/Gemfile b/Gemfile index 8e70288..171bf05 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem 'autoprefixer-rails' gem 'smart_listing' gem 'devise' gem 'cocoon' +gem 'turbolinks' group :development, :test do gem 'rspec-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 6ba0344..78af957 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -219,6 +219,8 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) + turbolinks (2.5.3) + coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.1) @@ -262,4 +264,5 @@ DEPENDENCIES shoulda-matchers simple_form smart_listing + turbolinks uglifier (>= 1.3.0) diff --git a/app/assets/javascripts/codes.coffee b/app/assets/javascripts/codes.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/codes.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://coffeescript.org/ diff --git a/app/assets/javascripts/conditions.coffee b/app/assets/javascripts/conditions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/conditions.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://coffeescript.org/ diff --git a/app/assets/javascripts/ingredients.coffee b/app/assets/javascripts/ingredients.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/ingredients.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://coffeescript.org/ diff --git a/app/assets/stylesheets/codes.scss b/app/assets/stylesheets/codes.scss new file mode 100644 index 0000000..374f8ff --- /dev/null +++ b/app/assets/stylesheets/codes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Codes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/conditions.scss b/app/assets/stylesheets/conditions.scss new file mode 100644 index 0000000..4d88ef4 --- /dev/null +++ b/app/assets/stylesheets/conditions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Conditions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/ingredients.scss b/app/assets/stylesheets/ingredients.scss new file mode 100644 index 0000000..1953e14 --- /dev/null +++ b/app/assets/stylesheets/ingredients.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Ingredients controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/app/controllers/codes_controller.rb b/app/controllers/codes_controller.rb new file mode 100644 index 0000000..56c4355 --- /dev/null +++ b/app/controllers/codes_controller.rb @@ -0,0 +1,58 @@ +class CodesController < ApplicationController + before_action :set_code, only: [:show, :edit, :update, :destroy] + + # GET /codes + def index + @codes = Code.all + end + + # GET /codes/1 + def show + end + + # GET /codes/new + def new + @code = Code.new + end + + # GET /codes/1/edit + def edit + end + + # POST /codes + def create + @code = Code.new(code_params) + + if @code.save + redirect_to @code, notice: 'Code was successfully created.' + else + render :new + end + end + + # PATCH/PUT /codes/1 + def update + if @code.update(code_params) + redirect_to @code, notice: 'Code was successfully updated.' + else + render :edit + end + end + + # DELETE /codes/1 + def destroy + @code.destroy + redirect_to codes_url, notice: 'Code was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_code + @code = Code.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def code_params + params.require(:code).permit(:code, :description) + end +end diff --git a/app/controllers/conditions_controller.rb b/app/controllers/conditions_controller.rb new file mode 100644 index 0000000..14c3f97 --- /dev/null +++ b/app/controllers/conditions_controller.rb @@ -0,0 +1,58 @@ +class ConditionsController < ApplicationController + before_action :set_condition, only: [:show, :edit, :update, :destroy] + + # GET /conditions + def index + @conditions = Condition.all + end + + # GET /conditions/1 + def show + end + + # GET /conditions/new + def new + @condition = Condition.new + end + + # GET /conditions/1/edit + def edit + end + + # POST /conditions + def create + @condition = Condition.new(condition_params) + + if @condition.save + redirect_to @condition, notice: 'Condition was successfully created.' + else + render :new + end + end + + # PATCH/PUT /conditions/1 + def update + if @condition.update(condition_params) + redirect_to @condition, notice: 'Condition was successfully updated.' + else + render :edit + end + end + + # DELETE /conditions/1 + def destroy + @condition.destroy + redirect_to conditions_url, notice: 'Condition was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_condition + @condition = Condition.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def condition_params + params.require(:condition).permit(:condition_name, :description) + end +end diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb new file mode 100644 index 0000000..9a81287 --- /dev/null +++ b/app/controllers/ingredients_controller.rb @@ -0,0 +1,58 @@ +class IngredientsController < ApplicationController + before_action :set_ingredient, only: [:show, :edit, :update, :destroy] + + # GET /ingredients + def index + @ingredients = Ingredient.all + end + + # GET /ingredients/1 + def show + end + + # GET /ingredients/new + def new + @ingredient = Ingredient.new + end + + # GET /ingredients/1/edit + def edit + end + + # POST /ingredients + def create + @ingredient = Ingredient.new(ingredient_params) + + if @ingredient.save + redirect_to @ingredient, notice: 'Ingredient was successfully created.' + else + render :new + end + end + + # PATCH/PUT /ingredients/1 + def update + if @ingredient.update(ingredient_params) + redirect_to @ingredient, notice: 'Ingredient was successfully updated.' + else + render :edit + end + end + + # DELETE /ingredients/1 + def destroy + @ingredient.destroy + redirect_to ingredients_url, notice: 'Ingredient was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_ingredient + @ingredient = Ingredient.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def ingredient_params + params.require(:ingredient).permit(:ingredient_name, :description) + end +end diff --git a/app/helpers/codes_helper.rb b/app/helpers/codes_helper.rb new file mode 100644 index 0000000..7373303 --- /dev/null +++ b/app/helpers/codes_helper.rb @@ -0,0 +1,2 @@ +module CodesHelper +end diff --git a/app/helpers/conditions_helper.rb b/app/helpers/conditions_helper.rb new file mode 100644 index 0000000..26355a8 --- /dev/null +++ b/app/helpers/conditions_helper.rb @@ -0,0 +1,2 @@ +module ConditionsHelper +end diff --git a/app/helpers/ingredients_helper.rb b/app/helpers/ingredients_helper.rb new file mode 100644 index 0000000..dd54783 --- /dev/null +++ b/app/helpers/ingredients_helper.rb @@ -0,0 +1,2 @@ +module IngredientsHelper +end diff --git a/app/models/code.rb b/app/models/code.rb new file mode 100644 index 0000000..e116a98 --- /dev/null +++ b/app/models/code.rb @@ -0,0 +1,2 @@ +class Code < ActiveRecord::Base +end diff --git a/app/models/condition.rb b/app/models/condition.rb new file mode 100644 index 0000000..1c98585 --- /dev/null +++ b/app/models/condition.rb @@ -0,0 +1,2 @@ +class Condition < ActiveRecord::Base +end diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb new file mode 100644 index 0000000..700e9ec --- /dev/null +++ b/app/models/ingredient.rb @@ -0,0 +1,2 @@ +class Ingredient < ActiveRecord::Base +end diff --git a/app/views/codes/_form.html.erb b/app/views/codes/_form.html.erb new file mode 100644 index 0000000..1a229ea --- /dev/null +++ b/app/views/codes/_form.html.erb @@ -0,0 +1,12 @@ +<%= simple_form_for(@code) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :code %> + <%= f.input :description %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/codes/edit.html.erb b/app/views/codes/edit.html.erb new file mode 100644 index 0000000..09c2357 --- /dev/null +++ b/app/views/codes/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Code

+ +<%= render 'form' %> + +<%= link_to 'Show', @code %> | +<%= link_to 'Back', codes_path %> diff --git a/app/views/codes/index.html.erb b/app/views/codes/index.html.erb new file mode 100644 index 0000000..47eaac7 --- /dev/null +++ b/app/views/codes/index.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

Listing Codes

+ + + + + + + + + + + + <% @codes.each do |code| %> + + + + + + + + <% end %> + +
CodeDescription
<%= code.code %><%= code.description %><%= link_to 'Show', code %><%= link_to 'Edit', edit_code_path(code) %><%= link_to 'Destroy', code, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Code', new_code_path %> diff --git a/app/views/codes/new.html.erb b/app/views/codes/new.html.erb new file mode 100644 index 0000000..b08f870 --- /dev/null +++ b/app/views/codes/new.html.erb @@ -0,0 +1,5 @@ +

New Code

+ +<%= render 'form' %> + +<%= link_to 'Back', codes_path %> diff --git a/app/views/codes/show.html.erb b/app/views/codes/show.html.erb new file mode 100644 index 0000000..485073b --- /dev/null +++ b/app/views/codes/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Code: + <%= @code.code %> +

+ +

+ Description: + <%= @code.description %> +

+ +<%= link_to 'Edit', edit_code_path(@code) %> | +<%= link_to 'Back', codes_path %> diff --git a/app/views/conditions/_form.html.erb b/app/views/conditions/_form.html.erb new file mode 100644 index 0000000..dd37954 --- /dev/null +++ b/app/views/conditions/_form.html.erb @@ -0,0 +1,12 @@ +<%= simple_form_for(@condition) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :condition_name %> + <%= f.input :description %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/conditions/edit.html.erb b/app/views/conditions/edit.html.erb new file mode 100644 index 0000000..99630f2 --- /dev/null +++ b/app/views/conditions/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Condition

+ +<%= render 'form' %> + +<%= link_to 'Show', @condition %> | +<%= link_to 'Back', conditions_path %> diff --git a/app/views/conditions/index.html.erb b/app/views/conditions/index.html.erb new file mode 100644 index 0000000..8ea2c22 --- /dev/null +++ b/app/views/conditions/index.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

Listing Conditions

+ + + + + + + + + + + + <% @conditions.each do |condition| %> + + + + + + + + <% end %> + +
Condition nameDescription
<%= condition.condition_name %><%= condition.description %><%= link_to 'Show', condition %><%= link_to 'Edit', edit_condition_path(condition) %><%= link_to 'Destroy', condition, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Condition', new_condition_path %> diff --git a/app/views/conditions/new.html.erb b/app/views/conditions/new.html.erb new file mode 100644 index 0000000..63a9f6b --- /dev/null +++ b/app/views/conditions/new.html.erb @@ -0,0 +1,5 @@ +

New Condition

+ +<%= render 'form' %> + +<%= link_to 'Back', conditions_path %> diff --git a/app/views/conditions/show.html.erb b/app/views/conditions/show.html.erb new file mode 100644 index 0000000..8ecf336 --- /dev/null +++ b/app/views/conditions/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Condition name: + <%= @condition.condition_name %> +

+ +

+ Description: + <%= @condition.description %> +

+ +<%= link_to 'Edit', edit_condition_path(@condition) %> | +<%= link_to 'Back', conditions_path %> diff --git a/app/views/ingredients/_form.html.erb b/app/views/ingredients/_form.html.erb new file mode 100644 index 0000000..385317b --- /dev/null +++ b/app/views/ingredients/_form.html.erb @@ -0,0 +1,12 @@ +<%= simple_form_for(@ingredient) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :ingredient_name %> + <%= f.input :description %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/ingredients/edit.html.erb b/app/views/ingredients/edit.html.erb new file mode 100644 index 0000000..36ab371 --- /dev/null +++ b/app/views/ingredients/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Ingredient

+ +<%= render 'form' %> + +<%= link_to 'Show', @ingredient %> | +<%= link_to 'Back', ingredients_path %> diff --git a/app/views/ingredients/index.html.erb b/app/views/ingredients/index.html.erb new file mode 100644 index 0000000..f5c322f --- /dev/null +++ b/app/views/ingredients/index.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

Listing Ingredients

+ + + + + + + + + + + + <% @ingredients.each do |ingredient| %> + + + + + + + + <% end %> + +
Ingredient nameDescription
<%= ingredient.ingredient_name %><%= ingredient.description %><%= link_to 'Show', ingredient %><%= link_to 'Edit', edit_ingredient_path(ingredient) %><%= link_to 'Destroy', ingredient, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Ingredient', new_ingredient_path %> diff --git a/app/views/ingredients/new.html.erb b/app/views/ingredients/new.html.erb new file mode 100644 index 0000000..fd63166 --- /dev/null +++ b/app/views/ingredients/new.html.erb @@ -0,0 +1,5 @@ +

New Ingredient

+ +<%= render 'form' %> + +<%= link_to 'Back', ingredients_path %> diff --git a/app/views/ingredients/show.html.erb b/app/views/ingredients/show.html.erb new file mode 100644 index 0000000..2ec781c --- /dev/null +++ b/app/views/ingredients/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Ingredient name: + <%= @ingredient.ingredient_name %> +

+ +

+ Description: + <%= @ingredient.description %> +

+ +<%= link_to 'Edit', edit_ingredient_path(@ingredient) %> | +<%= link_to 'Back', ingredients_path %> diff --git a/config/database.yml b/config/database.yml index 1c1a37c..1aa9517 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,16 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# default: &default - adapter: sqlite3 + adapter: postgresql + encoding: unicode pool: 5 timeout: 5000 development: <<: *default - database: db/development.sqlite3 + database: can_eat_this_development -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: +test: &test <<: *default - database: db/test.sqlite3 + database: can_eat_this_test -production: - <<: *default - database: db/production.sqlite3 +cucumber: + <<: *test diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100644 index 0000000..d5492e5 --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,166 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + # Wrappers are used by the form builder to generate a + # complete input. You can remove any component from the + # wrapper, change the order or even add your own to the + # stack. The options given below are used to wrap the + # whole input. + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors do |b| + ## Extensions enabled by default + # Any of these extensions can be disabled for a + # given input by passing: `f.input EXTENSION_NAME => false`. + # You can make any of these extensions optional by + # renaming `b.use` to `b.optional`. + + # Determines whether to use HTML5 (:email, :url, ...) + # and required attributes + b.use :html5 + + # Calculates placeholders automatically from I18n + # You can also pass a string as f.input placeholder: "Placeholder" + b.use :placeholder + + ## Optional extensions + # They are disabled unless you pass `f.input EXTENSION_NAME => true` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + b.optional :maxlength + + # Calculates pattern from format validations for string inputs + b.optional :pattern + + # Calculates min and max from length validations for numeric inputs + b.optional :min_max + + # Calculates readonly automatically from readonly attributes + b.optional :readonly + + ## Inputs + b.use :label_input + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } + + ## full_messages_for + # If you want to display the full error message for the attribute, you can + # use the component :full_error, like: + # + # b.use :full_error, wrap_with: { tag: :span, class: :error } + end + + # The default wrapper to be used by the FormBuilder. + config.default_wrapper = :default + + # Define the way to render check boxes / radio buttons with labels. + # Defaults to :nested for bootstrap config. + # inline: input + label + # nested: label > input + config.boolean_style = :nested + + # Default class for buttons + config.button_class = 'btn' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. + # config.error_method = :first + + # Default tag used for error notification helper. + config.error_notification_tag = :div + + # CSS class to add for error notification helper. + config.error_notification_class = 'error_notification' + + # ID to add for error notification helper. + # config.error_notification_id = nil + + # Series of attempts to detect a default label method for collection. + # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] + + # Series of attempts to detect a default value method for collection. + # config.collection_value_methods = [ :id, :to_s ] + + # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. + # config.collection_wrapper_tag = nil + + # You can define the class to use on all collection wrappers. Defaulting to none. + # config.collection_wrapper_class = nil + + # You can wrap each item in a collection of radio/check boxes with a tag, + # defaulting to :span. Please note that when using :boolean_style = :nested, + # SimpleForm will force this option to be a label. + # config.item_wrapper_tag = :span + + # You can define a class to use in all item wrappers. Defaulting to none. + # config.item_wrapper_class = nil + + # How the label text should be generated altogether with the required text. + # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + # config.label_class = nil + + # You can define the default class to be used on forms. Can be overriden + # with `html: { :class }`. Defaulting to none. + # config.default_form_class = nil + + # You can define which elements should obtain additional classes + # config.generate_additional_classes_for = [:wrapper, :label, :input] + + # Whether attributes are required by default (or not). Default is true. + # config.required_by_default = true + + # Tell browsers whether to use the native HTML5 validations (novalidate form option). + # These validations are enabled in SimpleForm's internal config but disabled by default + # in this configuration, which is recommended due to some quirks from different browsers. + # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, + # change this configuration to true. + config.browser_validations = false + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename ] + + # Custom mappings for input types. This should be a hash containing a regexp + # to match as key, and the input type that will be used when the field name + # matches the regexp as value. + # config.input_mappings = { /count/ => :integer } + + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + # config.wrapper_mappings = { string: :prepend } + + # Namespaces where SimpleForm should look for custom input classes that + # override default inputs. + # config.custom_inputs_namespaces << "CustomInputs" + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # When false, do not use translations for labels. + # config.translate_labels = true + + # Automatically discover new inputs in Rails' autoload path. + # config.inputs_discovery = true + + # Cache SimpleForm inputs discovery + # config.cache_discovery = !Rails.env.development? + + # Default class for inputs + # config.input_class = nil + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'checkbox' + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true + + # Defines which i18n scope will be used in Simple Form. + # config.i18n_scope = 'simple_form' +end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml new file mode 100644 index 0000000..2374383 --- /dev/null +++ b/config/locales/simple_form.en.yml @@ -0,0 +1,31 @@ +en: + simple_form: + "yes": 'Yes' + "no": 'No' + required: + text: 'required' + mark: '*' + # You can uncomment the line below if you need to overwrite the whole required html. + # When using html, text and mark won't be used. + # html: '*' + error_notification: + default_message: "Please review the problems below:" + # Examples + # labels: + # defaults: + # password: 'Password' + # user: + # new: + # email: 'E-mail to sign in.' + # edit: + # email: 'E-mail.' + # hints: + # defaults: + # username: 'User name to sign in.' + # password: 'No special characters, please.' + # include_blanks: + # defaults: + # age: 'Rather not say' + # prompts: + # defaults: + # age: 'Select your age' diff --git a/config/routes.rb b/config/routes.rb index 3f66539..87a229b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,10 @@ Rails.application.routes.draw do + resources :codes + + resources :ingredients + + resources :conditions + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20150528033848_create_conditions.rb b/db/migrate/20150528033848_create_conditions.rb new file mode 100644 index 0000000..e3abb01 --- /dev/null +++ b/db/migrate/20150528033848_create_conditions.rb @@ -0,0 +1,10 @@ +class CreateConditions < ActiveRecord::Migration + def change + create_table :conditions do |t| + t.string :condition_name + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20150528034145_create_ingredients.rb b/db/migrate/20150528034145_create_ingredients.rb new file mode 100644 index 0000000..1a904ec --- /dev/null +++ b/db/migrate/20150528034145_create_ingredients.rb @@ -0,0 +1,10 @@ +class CreateIngredients < ActiveRecord::Migration + def change + create_table :ingredients do |t| + t.string :ingredient_name + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20150528034336_create_codes.rb b/db/migrate/20150528034336_create_codes.rb new file mode 100644 index 0000000..5225509 --- /dev/null +++ b/db/migrate/20150528034336_create_codes.rb @@ -0,0 +1,10 @@ +class CreateCodes < ActiveRecord::Migration + def change + create_table :codes do |t| + t.string :code + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..54a34e0 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,40 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20150528034336) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "codes", force: :cascade do |t| + t.string "code" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "conditions", force: :cascade do |t| + t.string "condition_name" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "ingredients", force: :cascade do |t| + t.string "ingredient_name" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/lib/templates/erb/scaffold/_form.html.erb b/lib/templates/erb/scaffold/_form.html.erb new file mode 100644 index 0000000..201a069 --- /dev/null +++ b/lib/templates/erb/scaffold/_form.html.erb @@ -0,0 +1,13 @@ +<%%= simple_form_for(@<%= singular_table_name %>) do |f| %> + <%%= f.error_notification %> + +
+ <%- attributes.each do |attribute| -%> + <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %> + <%- end -%> +
+ +
+ <%%= f.button :submit %> +
+<%% end %> diff --git a/spec/controllers/codes_controller_spec.rb b/spec/controllers/codes_controller_spec.rb new file mode 100644 index 0000000..b0ce81f --- /dev/null +++ b/spec/controllers/codes_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe CodesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Code. As you add validations to Code, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # CodesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all codes as @codes" do + code = Code.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:codes)).to eq([code]) + end + end + + describe "GET #show" do + it "assigns the requested code as @code" do + code = Code.create! valid_attributes + get :show, {:id => code.to_param}, valid_session + expect(assigns(:code)).to eq(code) + end + end + + describe "GET #new" do + it "assigns a new code as @code" do + get :new, {}, valid_session + expect(assigns(:code)).to be_a_new(Code) + end + end + + describe "GET #edit" do + it "assigns the requested code as @code" do + code = Code.create! valid_attributes + get :edit, {:id => code.to_param}, valid_session + expect(assigns(:code)).to eq(code) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Code" do + expect { + post :create, {:code => valid_attributes}, valid_session + }.to change(Code, :count).by(1) + end + + it "assigns a newly created code as @code" do + post :create, {:code => valid_attributes}, valid_session + expect(assigns(:code)).to be_a(Code) + expect(assigns(:code)).to be_persisted + end + + it "redirects to the created code" do + post :create, {:code => valid_attributes}, valid_session + expect(response).to redirect_to(Code.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved code as @code" do + post :create, {:code => invalid_attributes}, valid_session + expect(assigns(:code)).to be_a_new(Code) + end + + it "re-renders the 'new' template" do + post :create, {:code => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested code" do + code = Code.create! valid_attributes + put :update, {:id => code.to_param, :code => new_attributes}, valid_session + code.reload + skip("Add assertions for updated state") + end + + it "assigns the requested code as @code" do + code = Code.create! valid_attributes + put :update, {:id => code.to_param, :code => valid_attributes}, valid_session + expect(assigns(:code)).to eq(code) + end + + it "redirects to the code" do + code = Code.create! valid_attributes + put :update, {:id => code.to_param, :code => valid_attributes}, valid_session + expect(response).to redirect_to(code) + end + end + + context "with invalid params" do + it "assigns the code as @code" do + code = Code.create! valid_attributes + put :update, {:id => code.to_param, :code => invalid_attributes}, valid_session + expect(assigns(:code)).to eq(code) + end + + it "re-renders the 'edit' template" do + code = Code.create! valid_attributes + put :update, {:id => code.to_param, :code => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested code" do + code = Code.create! valid_attributes + expect { + delete :destroy, {:id => code.to_param}, valid_session + }.to change(Code, :count).by(-1) + end + + it "redirects to the codes list" do + code = Code.create! valid_attributes + delete :destroy, {:id => code.to_param}, valid_session + expect(response).to redirect_to(codes_url) + end + end + +end diff --git a/spec/controllers/conditions_controller_spec.rb b/spec/controllers/conditions_controller_spec.rb new file mode 100644 index 0000000..865b4f5 --- /dev/null +++ b/spec/controllers/conditions_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe ConditionsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Condition. As you add validations to Condition, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # ConditionsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all conditions as @conditions" do + condition = Condition.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:conditions)).to eq([condition]) + end + end + + describe "GET #show" do + it "assigns the requested condition as @condition" do + condition = Condition.create! valid_attributes + get :show, {:id => condition.to_param}, valid_session + expect(assigns(:condition)).to eq(condition) + end + end + + describe "GET #new" do + it "assigns a new condition as @condition" do + get :new, {}, valid_session + expect(assigns(:condition)).to be_a_new(Condition) + end + end + + describe "GET #edit" do + it "assigns the requested condition as @condition" do + condition = Condition.create! valid_attributes + get :edit, {:id => condition.to_param}, valid_session + expect(assigns(:condition)).to eq(condition) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Condition" do + expect { + post :create, {:condition => valid_attributes}, valid_session + }.to change(Condition, :count).by(1) + end + + it "assigns a newly created condition as @condition" do + post :create, {:condition => valid_attributes}, valid_session + expect(assigns(:condition)).to be_a(Condition) + expect(assigns(:condition)).to be_persisted + end + + it "redirects to the created condition" do + post :create, {:condition => valid_attributes}, valid_session + expect(response).to redirect_to(Condition.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved condition as @condition" do + post :create, {:condition => invalid_attributes}, valid_session + expect(assigns(:condition)).to be_a_new(Condition) + end + + it "re-renders the 'new' template" do + post :create, {:condition => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested condition" do + condition = Condition.create! valid_attributes + put :update, {:id => condition.to_param, :condition => new_attributes}, valid_session + condition.reload + skip("Add assertions for updated state") + end + + it "assigns the requested condition as @condition" do + condition = Condition.create! valid_attributes + put :update, {:id => condition.to_param, :condition => valid_attributes}, valid_session + expect(assigns(:condition)).to eq(condition) + end + + it "redirects to the condition" do + condition = Condition.create! valid_attributes + put :update, {:id => condition.to_param, :condition => valid_attributes}, valid_session + expect(response).to redirect_to(condition) + end + end + + context "with invalid params" do + it "assigns the condition as @condition" do + condition = Condition.create! valid_attributes + put :update, {:id => condition.to_param, :condition => invalid_attributes}, valid_session + expect(assigns(:condition)).to eq(condition) + end + + it "re-renders the 'edit' template" do + condition = Condition.create! valid_attributes + put :update, {:id => condition.to_param, :condition => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested condition" do + condition = Condition.create! valid_attributes + expect { + delete :destroy, {:id => condition.to_param}, valid_session + }.to change(Condition, :count).by(-1) + end + + it "redirects to the conditions list" do + condition = Condition.create! valid_attributes + delete :destroy, {:id => condition.to_param}, valid_session + expect(response).to redirect_to(conditions_url) + end + end + +end diff --git a/spec/controllers/ingredients_controller_spec.rb b/spec/controllers/ingredients_controller_spec.rb new file mode 100644 index 0000000..95f2ae1 --- /dev/null +++ b/spec/controllers/ingredients_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe IngredientsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Ingredient. As you add validations to Ingredient, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # IngredientsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all ingredients as @ingredients" do + ingredient = Ingredient.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:ingredients)).to eq([ingredient]) + end + end + + describe "GET #show" do + it "assigns the requested ingredient as @ingredient" do + ingredient = Ingredient.create! valid_attributes + get :show, {:id => ingredient.to_param}, valid_session + expect(assigns(:ingredient)).to eq(ingredient) + end + end + + describe "GET #new" do + it "assigns a new ingredient as @ingredient" do + get :new, {}, valid_session + expect(assigns(:ingredient)).to be_a_new(Ingredient) + end + end + + describe "GET #edit" do + it "assigns the requested ingredient as @ingredient" do + ingredient = Ingredient.create! valid_attributes + get :edit, {:id => ingredient.to_param}, valid_session + expect(assigns(:ingredient)).to eq(ingredient) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Ingredient" do + expect { + post :create, {:ingredient => valid_attributes}, valid_session + }.to change(Ingredient, :count).by(1) + end + + it "assigns a newly created ingredient as @ingredient" do + post :create, {:ingredient => valid_attributes}, valid_session + expect(assigns(:ingredient)).to be_a(Ingredient) + expect(assigns(:ingredient)).to be_persisted + end + + it "redirects to the created ingredient" do + post :create, {:ingredient => valid_attributes}, valid_session + expect(response).to redirect_to(Ingredient.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved ingredient as @ingredient" do + post :create, {:ingredient => invalid_attributes}, valid_session + expect(assigns(:ingredient)).to be_a_new(Ingredient) + end + + it "re-renders the 'new' template" do + post :create, {:ingredient => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested ingredient" do + ingredient = Ingredient.create! valid_attributes + put :update, {:id => ingredient.to_param, :ingredient => new_attributes}, valid_session + ingredient.reload + skip("Add assertions for updated state") + end + + it "assigns the requested ingredient as @ingredient" do + ingredient = Ingredient.create! valid_attributes + put :update, {:id => ingredient.to_param, :ingredient => valid_attributes}, valid_session + expect(assigns(:ingredient)).to eq(ingredient) + end + + it "redirects to the ingredient" do + ingredient = Ingredient.create! valid_attributes + put :update, {:id => ingredient.to_param, :ingredient => valid_attributes}, valid_session + expect(response).to redirect_to(ingredient) + end + end + + context "with invalid params" do + it "assigns the ingredient as @ingredient" do + ingredient = Ingredient.create! valid_attributes + put :update, {:id => ingredient.to_param, :ingredient => invalid_attributes}, valid_session + expect(assigns(:ingredient)).to eq(ingredient) + end + + it "re-renders the 'edit' template" do + ingredient = Ingredient.create! valid_attributes + put :update, {:id => ingredient.to_param, :ingredient => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested ingredient" do + ingredient = Ingredient.create! valid_attributes + expect { + delete :destroy, {:id => ingredient.to_param}, valid_session + }.to change(Ingredient, :count).by(-1) + end + + it "redirects to the ingredients list" do + ingredient = Ingredient.create! valid_attributes + delete :destroy, {:id => ingredient.to_param}, valid_session + expect(response).to redirect_to(ingredients_url) + end + end + +end diff --git a/spec/factories/codes.rb b/spec/factories/codes.rb new file mode 100644 index 0000000..90918b4 --- /dev/null +++ b/spec/factories/codes.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :code do + code "MyString" +description "MyString" + end + +end diff --git a/spec/factories/conditions.rb b/spec/factories/conditions.rb new file mode 100644 index 0000000..0bf3bef --- /dev/null +++ b/spec/factories/conditions.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :condition do + condition_name "MyString" +description "MyString" + end + +end diff --git a/spec/factories/ingredients.rb b/spec/factories/ingredients.rb new file mode 100644 index 0000000..7beee1c --- /dev/null +++ b/spec/factories/ingredients.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ingredient do + ingredient_name "MyString" +description "MyString" + end + +end diff --git a/spec/helpers/codes_helper_spec.rb b/spec/helpers/codes_helper_spec.rb new file mode 100644 index 0000000..6f14a84 --- /dev/null +++ b/spec/helpers/codes_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CodesHelper. For example: +# +# describe CodesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe CodesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/conditions_helper_spec.rb b/spec/helpers/conditions_helper_spec.rb new file mode 100644 index 0000000..43a51dc --- /dev/null +++ b/spec/helpers/conditions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ConditionsHelper. For example: +# +# describe ConditionsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ConditionsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/ingredients_helper_spec.rb b/spec/helpers/ingredients_helper_spec.rb new file mode 100644 index 0000000..0a9ee8a --- /dev/null +++ b/spec/helpers/ingredients_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the IngredientsHelper. For example: +# +# describe IngredientsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe IngredientsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/code_spec.rb b/spec/models/code_spec.rb new file mode 100644 index 0000000..f22f1c6 --- /dev/null +++ b/spec/models/code_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Code, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/condition_spec.rb b/spec/models/condition_spec.rb new file mode 100644 index 0000000..bcf85ec --- /dev/null +++ b/spec/models/condition_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Condition, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/ingredient_spec.rb b/spec/models/ingredient_spec.rb new file mode 100644 index 0000000..0dc0383 --- /dev/null +++ b/spec/models/ingredient_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Ingredient, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/codes_spec.rb b/spec/requests/codes_spec.rb new file mode 100644 index 0000000..cde03c9 --- /dev/null +++ b/spec/requests/codes_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Codes", type: :request do + describe "GET /codes" do + it "works! (now write some real specs)" do + get codes_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/conditions_spec.rb b/spec/requests/conditions_spec.rb new file mode 100644 index 0000000..d0a7eb5 --- /dev/null +++ b/spec/requests/conditions_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Conditions", type: :request do + describe "GET /conditions" do + it "works! (now write some real specs)" do + get conditions_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/requests/ingredients_spec.rb b/spec/requests/ingredients_spec.rb new file mode 100644 index 0000000..1181aba --- /dev/null +++ b/spec/requests/ingredients_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Ingredients", type: :request do + describe "GET /ingredients" do + it "works! (now write some real specs)" do + get ingredients_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/codes_routing_spec.rb b/spec/routing/codes_routing_spec.rb new file mode 100644 index 0000000..533479f --- /dev/null +++ b/spec/routing/codes_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe CodesController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/codes").to route_to("codes#index") + end + + it "routes to #new" do + expect(:get => "/codes/new").to route_to("codes#new") + end + + it "routes to #show" do + expect(:get => "/codes/1").to route_to("codes#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/codes/1/edit").to route_to("codes#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/codes").to route_to("codes#create") + end + + it "routes to #update" do + expect(:put => "/codes/1").to route_to("codes#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/codes/1").to route_to("codes#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/conditions_routing_spec.rb b/spec/routing/conditions_routing_spec.rb new file mode 100644 index 0000000..cc2a90f --- /dev/null +++ b/spec/routing/conditions_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe ConditionsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/conditions").to route_to("conditions#index") + end + + it "routes to #new" do + expect(:get => "/conditions/new").to route_to("conditions#new") + end + + it "routes to #show" do + expect(:get => "/conditions/1").to route_to("conditions#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/conditions/1/edit").to route_to("conditions#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/conditions").to route_to("conditions#create") + end + + it "routes to #update" do + expect(:put => "/conditions/1").to route_to("conditions#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/conditions/1").to route_to("conditions#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/ingredients_routing_spec.rb b/spec/routing/ingredients_routing_spec.rb new file mode 100644 index 0000000..1d752fe --- /dev/null +++ b/spec/routing/ingredients_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe IngredientsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/ingredients").to route_to("ingredients#index") + end + + it "routes to #new" do + expect(:get => "/ingredients/new").to route_to("ingredients#new") + end + + it "routes to #show" do + expect(:get => "/ingredients/1").to route_to("ingredients#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/ingredients/1/edit").to route_to("ingredients#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/ingredients").to route_to("ingredients#create") + end + + it "routes to #update" do + expect(:put => "/ingredients/1").to route_to("ingredients#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/ingredients/1").to route_to("ingredients#destroy", :id => "1") + end + + end +end diff --git a/spec/views/codes/edit.html.erb_spec.rb b/spec/views/codes/edit.html.erb_spec.rb new file mode 100644 index 0000000..91dabba --- /dev/null +++ b/spec/views/codes/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "codes/edit", type: :view do + before(:each) do + @code = assign(:code, Code.create!( + :code => "MyString", + :description => "MyString" + )) + end + + it "renders the edit code form" do + render + + assert_select "form[action=?][method=?]", code_path(@code), "post" do + + assert_select "input#code_code[name=?]", "code[code]" + + assert_select "input#code_description[name=?]", "code[description]" + end + end +end diff --git a/spec/views/codes/index.html.erb_spec.rb b/spec/views/codes/index.html.erb_spec.rb new file mode 100644 index 0000000..facc112 --- /dev/null +++ b/spec/views/codes/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "codes/index", type: :view do + before(:each) do + assign(:codes, [ + Code.create!( + :code => "Code", + :description => "Description" + ), + Code.create!( + :code => "Code", + :description => "Description" + ) + ]) + end + + it "renders a list of codes" do + render + assert_select "tr>td", :text => "Code".to_s, :count => 2 + assert_select "tr>td", :text => "Description".to_s, :count => 2 + end +end diff --git a/spec/views/codes/new.html.erb_spec.rb b/spec/views/codes/new.html.erb_spec.rb new file mode 100644 index 0000000..5bd5cde --- /dev/null +++ b/spec/views/codes/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "codes/new", type: :view do + before(:each) do + assign(:code, Code.new( + :code => "MyString", + :description => "MyString" + )) + end + + it "renders new code form" do + render + + assert_select "form[action=?][method=?]", codes_path, "post" do + + assert_select "input#code_code[name=?]", "code[code]" + + assert_select "input#code_description[name=?]", "code[description]" + end + end +end diff --git a/spec/views/codes/show.html.erb_spec.rb b/spec/views/codes/show.html.erb_spec.rb new file mode 100644 index 0000000..77d4506 --- /dev/null +++ b/spec/views/codes/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "codes/show", type: :view do + before(:each) do + @code = assign(:code, Code.create!( + :code => "Code", + :description => "Description" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Code/) + expect(rendered).to match(/Description/) + end +end diff --git a/spec/views/conditions/edit.html.erb_spec.rb b/spec/views/conditions/edit.html.erb_spec.rb new file mode 100644 index 0000000..26b2520 --- /dev/null +++ b/spec/views/conditions/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "conditions/edit", type: :view do + before(:each) do + @condition = assign(:condition, Condition.create!( + :condition_name => "MyString", + :description => "MyString" + )) + end + + it "renders the edit condition form" do + render + + assert_select "form[action=?][method=?]", condition_path(@condition), "post" do + + assert_select "input#condition_condition_name[name=?]", "condition[condition_name]" + + assert_select "input#condition_description[name=?]", "condition[description]" + end + end +end diff --git a/spec/views/conditions/index.html.erb_spec.rb b/spec/views/conditions/index.html.erb_spec.rb new file mode 100644 index 0000000..f7cbbab --- /dev/null +++ b/spec/views/conditions/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "conditions/index", type: :view do + before(:each) do + assign(:conditions, [ + Condition.create!( + :condition_name => "Condition Name", + :description => "Description" + ), + Condition.create!( + :condition_name => "Condition Name", + :description => "Description" + ) + ]) + end + + it "renders a list of conditions" do + render + assert_select "tr>td", :text => "Condition Name".to_s, :count => 2 + assert_select "tr>td", :text => "Description".to_s, :count => 2 + end +end diff --git a/spec/views/conditions/new.html.erb_spec.rb b/spec/views/conditions/new.html.erb_spec.rb new file mode 100644 index 0000000..ae13b29 --- /dev/null +++ b/spec/views/conditions/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "conditions/new", type: :view do + before(:each) do + assign(:condition, Condition.new( + :condition_name => "MyString", + :description => "MyString" + )) + end + + it "renders new condition form" do + render + + assert_select "form[action=?][method=?]", conditions_path, "post" do + + assert_select "input#condition_condition_name[name=?]", "condition[condition_name]" + + assert_select "input#condition_description[name=?]", "condition[description]" + end + end +end diff --git a/spec/views/conditions/show.html.erb_spec.rb b/spec/views/conditions/show.html.erb_spec.rb new file mode 100644 index 0000000..c4fb6ce --- /dev/null +++ b/spec/views/conditions/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "conditions/show", type: :view do + before(:each) do + @condition = assign(:condition, Condition.create!( + :condition_name => "Condition Name", + :description => "Description" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Condition Name/) + expect(rendered).to match(/Description/) + end +end diff --git a/spec/views/ingredients/edit.html.erb_spec.rb b/spec/views/ingredients/edit.html.erb_spec.rb new file mode 100644 index 0000000..d0d7bf1 --- /dev/null +++ b/spec/views/ingredients/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "ingredients/edit", type: :view do + before(:each) do + @ingredient = assign(:ingredient, Ingredient.create!( + :ingredient_name => "MyString", + :description => "MyString" + )) + end + + it "renders the edit ingredient form" do + render + + assert_select "form[action=?][method=?]", ingredient_path(@ingredient), "post" do + + assert_select "input#ingredient_ingredient_name[name=?]", "ingredient[ingredient_name]" + + assert_select "input#ingredient_description[name=?]", "ingredient[description]" + end + end +end diff --git a/spec/views/ingredients/index.html.erb_spec.rb b/spec/views/ingredients/index.html.erb_spec.rb new file mode 100644 index 0000000..6529716 --- /dev/null +++ b/spec/views/ingredients/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "ingredients/index", type: :view do + before(:each) do + assign(:ingredients, [ + Ingredient.create!( + :ingredient_name => "Ingredient Name", + :description => "Description" + ), + Ingredient.create!( + :ingredient_name => "Ingredient Name", + :description => "Description" + ) + ]) + end + + it "renders a list of ingredients" do + render + assert_select "tr>td", :text => "Ingredient Name".to_s, :count => 2 + assert_select "tr>td", :text => "Description".to_s, :count => 2 + end +end diff --git a/spec/views/ingredients/new.html.erb_spec.rb b/spec/views/ingredients/new.html.erb_spec.rb new file mode 100644 index 0000000..5faa0a6 --- /dev/null +++ b/spec/views/ingredients/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "ingredients/new", type: :view do + before(:each) do + assign(:ingredient, Ingredient.new( + :ingredient_name => "MyString", + :description => "MyString" + )) + end + + it "renders new ingredient form" do + render + + assert_select "form[action=?][method=?]", ingredients_path, "post" do + + assert_select "input#ingredient_ingredient_name[name=?]", "ingredient[ingredient_name]" + + assert_select "input#ingredient_description[name=?]", "ingredient[description]" + end + end +end diff --git a/spec/views/ingredients/show.html.erb_spec.rb b/spec/views/ingredients/show.html.erb_spec.rb new file mode 100644 index 0000000..6c5f741 --- /dev/null +++ b/spec/views/ingredients/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "ingredients/show", type: :view do + before(:each) do + @ingredient = assign(:ingredient, Ingredient.create!( + :ingredient_name => "Ingredient Name", + :description => "Description" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Ingredient Name/) + expect(rendered).to match(/Description/) + end +end