diff --git a/app/assets/javascripts/cursos.js.coffee b/app/assets/javascripts/cursos.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/cursos.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/cursos.css.scss b/app/assets/stylesheets/cursos.css.scss new file mode 100644 index 0000000..9bf6865 --- /dev/null +++ b/app/assets/stylesheets/cursos.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Cursos 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.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..05188f0 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,56 @@ +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/cursos_controller.rb b/app/controllers/cursos_controller.rb new file mode 100644 index 0000000..5bb9023 --- /dev/null +++ b/app/controllers/cursos_controller.rb @@ -0,0 +1,83 @@ +class CursosController < ApplicationController + # GET /cursos + # GET /cursos.json + def index + @cursos = Curso.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @cursos } + end + end + + # GET /cursos/1 + # GET /cursos/1.json + def show + @curso = Curso.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @curso } + end + end + + # GET /cursos/new + # GET /cursos/new.json + def new + @curso = Curso.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @curso } + end + end + + # GET /cursos/1/edit + def edit + @curso = Curso.find(params[:id]) + end + + # POST /cursos + # POST /cursos.json + def create + @curso = Curso.new(params[:curso]) + + respond_to do |format| + if @curso.save + format.html { redirect_to @curso, notice: 'Curso was successfully created.' } + format.json { render json: @curso, status: :created, location: @curso } + else + format.html { render action: "new" } + format.json { render json: @curso.errors, status: :unprocessable_entity } + end + end + end + + # PUT /cursos/1 + # PUT /cursos/1.json + def update + @curso = Curso.find(params[:id]) + + respond_to do |format| + if @curso.update_attributes(params[:curso]) + format.html { redirect_to @curso, notice: 'Curso was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @curso.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /cursos/1 + # DELETE /cursos/1.json + def destroy + @curso = Curso.find(params[:id]) + @curso.destroy + + respond_to do |format| + format.html { redirect_to cursos_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/cursos_helper.rb b/app/helpers/cursos_helper.rb new file mode 100644 index 0000000..4921eff --- /dev/null +++ b/app/helpers/cursos_helper.rb @@ -0,0 +1,2 @@ +module CursosHelper +end diff --git a/app/models/curso.rb b/app/models/curso.rb new file mode 100644 index 0000000..0e84d21 --- /dev/null +++ b/app/models/curso.rb @@ -0,0 +1,2 @@ +class Curso < ActiveRecord::Base +end diff --git a/app/views/cursos/_form.html.erb b/app/views/cursos/_form.html.erb new file mode 100644 index 0000000..84db34c --- /dev/null +++ b/app/views/cursos/_form.html.erb @@ -0,0 +1,37 @@ +<%= form_for(@curso) do |f| %> + <% if @curso.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :nombre %>
+ <%= f.text_field :nombre %> +
+
+ <%= f.label :formula %>
+ <%= f.text_field :formula %> +
+
+ <%= f.label :cantpcs %>
+ <%= f.number_field :cantpcs %> +
+
+ <%= f.label :exafinal %>
+ <%= f.check_box :exafinal %> +
+
+ <%= f.label :proyecto %>
+ <%= f.check_box :proyecto %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/cursos/edit.html.erb b/app/views/cursos/edit.html.erb new file mode 100644 index 0000000..0333bf3 --- /dev/null +++ b/app/views/cursos/edit.html.erb @@ -0,0 +1,6 @@ +

Editing curso

+ +<%= render 'form' %> + +<%= link_to 'Show', @curso %> | +<%= link_to 'Back', cursos_path %> diff --git a/app/views/cursos/index.html.erb b/app/views/cursos/index.html.erb new file mode 100644 index 0000000..026dbaf --- /dev/null +++ b/app/views/cursos/index.html.erb @@ -0,0 +1,31 @@ +

Listing cursos

+ + + + + + + + + + + + + +<% @cursos.each do |curso| %> + + + + + + + + + + +<% end %> +
NombreFormulaCantpcsExafinalProyecto
<%= curso.nombre %><%= curso.formula %><%= curso.cantpcs %><%= curso.exafinal %><%= curso.proyecto %><%= link_to 'Show', curso %><%= link_to 'Edit', edit_curso_path(curso) %><%= link_to 'Destroy', curso, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Curso', new_curso_path %> diff --git a/app/views/cursos/new.html.erb b/app/views/cursos/new.html.erb new file mode 100644 index 0000000..fa2f976 --- /dev/null +++ b/app/views/cursos/new.html.erb @@ -0,0 +1,5 @@ +

New curso

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

<%= notice %>

+ +

+ Nombre: + <%= @curso.nombre %> +

+ +

+ Formula: + <%= @curso.formula %> +

+ +

+ Cantpcs: + <%= @curso.cantpcs %> +

+ +

+ Exafinal: + <%= @curso.exafinal %> +

+ +

+ Proyecto: + <%= @curso.proyecto %> +

+ + +<%= link_to 'Edit', edit_curso_path(@curso) %> | +<%= link_to 'Back', cursos_path %> diff --git a/config/routes.rb b/config/routes.rb index 5ce4542..caf08a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ TDEW2012::Application.routes.draw do + resources :cursos + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/db/migrate/20120317220952_create_cursos.rb b/db/migrate/20120317220952_create_cursos.rb new file mode 100644 index 0000000..b41eb22 --- /dev/null +++ b/db/migrate/20120317220952_create_cursos.rb @@ -0,0 +1,13 @@ +class CreateCursos < ActiveRecord::Migration + def change + create_table :cursos do |t| + t.string :nombre + t.string :formula + t.integer :cantpcs + t.boolean :exafinal + t.boolean :proyecto + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..7dc6079 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# 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 to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20120317220952) do + + create_table "cursos", :force => true do |t| + t.string "nombre" + t.string "formula" + t.integer "cantpcs" + t.boolean "exafinal" + t.boolean "proyecto" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + +end diff --git a/test/fixtures/cursos.yml b/test/fixtures/cursos.yml new file mode 100644 index 0000000..0201d28 --- /dev/null +++ b/test/fixtures/cursos.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + nombre: MyString + formula: MyString + cantpcs: 1 + exafinal: false + proyecto: false + +two: + nombre: MyString + formula: MyString + cantpcs: 1 + exafinal: false + proyecto: false diff --git a/test/functional/cursos_controller_test.rb b/test/functional/cursos_controller_test.rb new file mode 100644 index 0000000..ac7ee87 --- /dev/null +++ b/test/functional/cursos_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class CursosControllerTest < ActionController::TestCase + setup do + @curso = cursos(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:cursos) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create curso" do + assert_difference('Curso.count') do + post :create, curso: @curso.attributes + end + + assert_redirected_to curso_path(assigns(:curso)) + end + + test "should show curso" do + get :show, id: @curso + assert_response :success + end + + test "should get edit" do + get :edit, id: @curso + assert_response :success + end + + test "should update curso" do + put :update, id: @curso, curso: @curso.attributes + assert_redirected_to curso_path(assigns(:curso)) + end + + test "should destroy curso" do + assert_difference('Curso.count', -1) do + delete :destroy, id: @curso + end + + assert_redirected_to cursos_path + end +end diff --git a/test/unit/curso_test.rb b/test/unit/curso_test.rb new file mode 100644 index 0000000..4f3f666 --- /dev/null +++ b/test/unit/curso_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CursoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/cursos_helper_test.rb b/test/unit/helpers/cursos_helper_test.rb new file mode 100644 index 0000000..ddeafdf --- /dev/null +++ b/test/unit/helpers/cursos_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CursosHelperTest < ActionView::TestCase +end