From 87741bac314e393d1f45c6924cb980c3a30613e2 Mon Sep 17 00:00:00 2001 From: ahinz Date: Wed, 9 Oct 2013 11:47:04 +0200 Subject: [PATCH] Signed-off-by: ahinz --- app/assets/javascripts/gem_crafts.js.coffee | 3 + app/assets/stylesheets/gem_crafts.css.scss | 3 + app/controllers/gem_crafts_controller.rb | 74 +++++++++++++++++++ app/helpers/gem_crafts_helper.rb | 2 + app/models/gem_craft.rb | 2 + app/views/gem_crafts/_form.html.erb | 41 ++++++++++ app/views/gem_crafts/edit.html.erb | 6 ++ app/views/gem_crafts/index.html.erb | 37 ++++++++++ app/views/gem_crafts/index.json.jbuilder | 4 + app/views/gem_crafts/new.html.erb | 5 ++ app/views/gem_crafts/show.html.erb | 34 +++++++++ app/views/gem_crafts/show.json.jbuilder | 1 + .../20131009084203_create_gem_crafts.rb | 14 ++++ .../controllers/gem_crafts_controller_test.rb | 49 ++++++++++++ test/fixtures/gem_crafts.yml | 17 +++++ test/helpers/gem_crafts_helper_test.rb | 4 + test/models/gem_craft_test.rb | 7 ++ 17 files changed, 303 insertions(+) create mode 100644 app/assets/javascripts/gem_crafts.js.coffee create mode 100644 app/assets/stylesheets/gem_crafts.css.scss create mode 100644 app/controllers/gem_crafts_controller.rb create mode 100644 app/helpers/gem_crafts_helper.rb create mode 100644 app/models/gem_craft.rb create mode 100644 app/views/gem_crafts/_form.html.erb create mode 100644 app/views/gem_crafts/edit.html.erb create mode 100644 app/views/gem_crafts/index.html.erb create mode 100644 app/views/gem_crafts/index.json.jbuilder create mode 100644 app/views/gem_crafts/new.html.erb create mode 100644 app/views/gem_crafts/show.html.erb create mode 100644 app/views/gem_crafts/show.json.jbuilder create mode 100644 db/migrate/20131009084203_create_gem_crafts.rb create mode 100644 test/controllers/gem_crafts_controller_test.rb create mode 100644 test/fixtures/gem_crafts.yml create mode 100644 test/helpers/gem_crafts_helper_test.rb create mode 100644 test/models/gem_craft_test.rb diff --git a/app/assets/javascripts/gem_crafts.js.coffee b/app/assets/javascripts/gem_crafts.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/gem_crafts.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://coffeescript.org/ diff --git a/app/assets/stylesheets/gem_crafts.css.scss b/app/assets/stylesheets/gem_crafts.css.scss new file mode 100644 index 0000000..14480a7 --- /dev/null +++ b/app/assets/stylesheets/gem_crafts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the GemCrafts 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/gem_crafts_controller.rb b/app/controllers/gem_crafts_controller.rb new file mode 100644 index 0000000..457d0c9 --- /dev/null +++ b/app/controllers/gem_crafts_controller.rb @@ -0,0 +1,74 @@ +class GemCraftsController < ApplicationController + before_action :set_gem_craft, only: [:show, :edit, :update, :destroy] + + # GET /gem_crafts + # GET /gem_crafts.json + def index + @gem_crafts = GemCraft.all + end + + # GET /gem_crafts/1 + # GET /gem_crafts/1.json + def show + end + + # GET /gem_crafts/new + def new + @gem_craft = GemCraft.new + end + + # GET /gem_crafts/1/edit + def edit + end + + # POST /gem_crafts + # POST /gem_crafts.json + def create + @gem_craft = GemCraft.new(gem_craft_params) + + respond_to do |format| + if @gem_craft.save + format.html { redirect_to @gem_craft, notice: 'Gem craft was successfully created.' } + format.json { render action: 'show', status: :created, location: @gem_craft } + else + format.html { render action: 'new' } + format.json { render json: @gem_craft.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /gem_crafts/1 + # PATCH/PUT /gem_crafts/1.json + def update + respond_to do |format| + if @gem_craft.update(gem_craft_params) + format.html { redirect_to @gem_craft, notice: 'Gem craft was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @gem_craft.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /gem_crafts/1 + # DELETE /gem_crafts/1.json + def destroy + @gem_craft.destroy + respond_to do |format| + format.html { redirect_to gem_crafts_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_gem_craft + @gem_craft = GemCraft.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def gem_craft_params + params.require(:gem_craft).permit(:name, :price, :books_type, :books_qnt, :previous_id, :previous_qnt) + end +end diff --git a/app/helpers/gem_crafts_helper.rb b/app/helpers/gem_crafts_helper.rb new file mode 100644 index 0000000..6dc9687 --- /dev/null +++ b/app/helpers/gem_crafts_helper.rb @@ -0,0 +1,2 @@ +module GemCraftsHelper +end diff --git a/app/models/gem_craft.rb b/app/models/gem_craft.rb new file mode 100644 index 0000000..b999538 --- /dev/null +++ b/app/models/gem_craft.rb @@ -0,0 +1,2 @@ +class GemCraft < ActiveRecord::Base +end diff --git a/app/views/gem_crafts/_form.html.erb b/app/views/gem_crafts/_form.html.erb new file mode 100644 index 0000000..26dad42 --- /dev/null +++ b/app/views/gem_crafts/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for(@gem_craft) do |f| %> + <% if @gem_craft.errors.any? %> +
+

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

+ +
    + <% @gem_craft.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :price %>
+ <%= f.number_field :price %> +
+
+ <%= f.label :books_type %>
+ <%= f.number_field :books_type %> +
+
+ <%= f.label :books_qnt %>
+ <%= f.number_field :books_qnt %> +
+
+ <%= f.label :previous_id %>
+ <%= f.number_field :previous_id %> +
+
+ <%= f.label :previous_qnt %>
+ <%= f.number_field :previous_qnt %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/gem_crafts/edit.html.erb b/app/views/gem_crafts/edit.html.erb new file mode 100644 index 0000000..801ffb9 --- /dev/null +++ b/app/views/gem_crafts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing gem_craft

+ +<%= render 'form' %> + +<%= link_to 'Show', @gem_craft %> | +<%= link_to 'Back', gem_crafts_path %> diff --git a/app/views/gem_crafts/index.html.erb b/app/views/gem_crafts/index.html.erb new file mode 100644 index 0000000..8a6ab48 --- /dev/null +++ b/app/views/gem_crafts/index.html.erb @@ -0,0 +1,37 @@ +

Listing gem_crafts

+ + + + + + + + + + + + + + + + + + <% @gem_crafts.each do |gem_craft| %> + + + + + + + + + + + + <% end %> + +
NamePriceBooks typeBooks qntPreviousPrevious qnt
<%= gem_craft.name %><%= gem_craft.price %><%= gem_craft.books_type %><%= gem_craft.books_qnt %><%= gem_craft.previous_id %><%= gem_craft.previous_qnt %><%= link_to 'Show', gem_craft %><%= link_to 'Edit', edit_gem_craft_path(gem_craft) %><%= link_to 'Destroy', gem_craft, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Gem craft', new_gem_craft_path %> diff --git a/app/views/gem_crafts/index.json.jbuilder b/app/views/gem_crafts/index.json.jbuilder new file mode 100644 index 0000000..e26bf5c --- /dev/null +++ b/app/views/gem_crafts/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@gem_crafts) do |gem_craft| + json.extract! gem_craft, :name, :price, :books_type, :books_qnt, :previous_id, :previous_qnt + json.url gem_craft_url(gem_craft, format: :json) +end diff --git a/app/views/gem_crafts/new.html.erb b/app/views/gem_crafts/new.html.erb new file mode 100644 index 0000000..0aa9bfa --- /dev/null +++ b/app/views/gem_crafts/new.html.erb @@ -0,0 +1,5 @@ +

New gem_craft

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

<%= notice %>

+ +

+ Name: + <%= @gem_craft.name %> +

+ +

+ Price: + <%= @gem_craft.price %> +

+ +

+ Books type: + <%= @gem_craft.books_type %> +

+ +

+ Books qnt: + <%= @gem_craft.books_qnt %> +

+ +

+ Previous: + <%= @gem_craft.previous_id %> +

+ +

+ Previous qnt: + <%= @gem_craft.previous_qnt %> +

+ +<%= link_to 'Edit', edit_gem_craft_path(@gem_craft) %> | +<%= link_to 'Back', gem_crafts_path %> diff --git a/app/views/gem_crafts/show.json.jbuilder b/app/views/gem_crafts/show.json.jbuilder new file mode 100644 index 0000000..5371cbe --- /dev/null +++ b/app/views/gem_crafts/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @gem_craft, :name, :price, :books_type, :books_qnt, :previous_id, :previous_qnt, :created_at, :updated_at diff --git a/db/migrate/20131009084203_create_gem_crafts.rb b/db/migrate/20131009084203_create_gem_crafts.rb new file mode 100644 index 0000000..7f1684d --- /dev/null +++ b/db/migrate/20131009084203_create_gem_crafts.rb @@ -0,0 +1,14 @@ +class CreateGemCrafts < ActiveRecord::Migration + def change + create_table :gem_crafts do |t| + t.string :name + t.integer :price + t.integer :books_type + t.integer :books_qnt + t.integer :previous_id + t.integer :previous_qnt + + t.timestamps + end + end +end diff --git a/test/controllers/gem_crafts_controller_test.rb b/test/controllers/gem_crafts_controller_test.rb new file mode 100644 index 0000000..69b9609 --- /dev/null +++ b/test/controllers/gem_crafts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class GemCraftsControllerTest < ActionController::TestCase + setup do + @gem_craft = gem_crafts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:gem_crafts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create gem_craft" do + assert_difference('GemCraft.count') do + post :create, gem_craft: { books_qnt: @gem_craft.books_qnt, books_type: @gem_craft.books_type, name: @gem_craft.name, previous_id: @gem_craft.previous_id, previous_qnt: @gem_craft.previous_qnt, price: @gem_craft.price } + end + + assert_redirected_to gem_craft_path(assigns(:gem_craft)) + end + + test "should show gem_craft" do + get :show, id: @gem_craft + assert_response :success + end + + test "should get edit" do + get :edit, id: @gem_craft + assert_response :success + end + + test "should update gem_craft" do + patch :update, id: @gem_craft, gem_craft: { books_qnt: @gem_craft.books_qnt, books_type: @gem_craft.books_type, name: @gem_craft.name, previous_id: @gem_craft.previous_id, previous_qnt: @gem_craft.previous_qnt, price: @gem_craft.price } + assert_redirected_to gem_craft_path(assigns(:gem_craft)) + end + + test "should destroy gem_craft" do + assert_difference('GemCraft.count', -1) do + delete :destroy, id: @gem_craft + end + + assert_redirected_to gem_crafts_path + end +end diff --git a/test/fixtures/gem_crafts.yml b/test/fixtures/gem_crafts.yml new file mode 100644 index 0000000..a86372a --- /dev/null +++ b/test/fixtures/gem_crafts.yml @@ -0,0 +1,17 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + name: MyString + price: 1 + books_type: 1 + books_qnt: 1 + previous_id: 1 + previous_qnt: 1 + +two: + name: MyString + price: 1 + books_type: 1 + books_qnt: 1 + previous_id: 1 + previous_qnt: 1 diff --git a/test/helpers/gem_crafts_helper_test.rb b/test/helpers/gem_crafts_helper_test.rb new file mode 100644 index 0000000..d89f10b --- /dev/null +++ b/test/helpers/gem_crafts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class GemCraftsHelperTest < ActionView::TestCase +end diff --git a/test/models/gem_craft_test.rb b/test/models/gem_craft_test.rb new file mode 100644 index 0000000..30a0599 --- /dev/null +++ b/test/models/gem_craft_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class GemCraftTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end