...
 
Commits (18)
......@@ -18,3 +18,9 @@
# Ignore local gems from bundler
vendor/bundle/*
# Ignore current schema
db/schema.rb
# Ignore Gemfile lock
Gemfile.lock
......@@ -32,6 +32,12 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Fast CSV to parse CSV files
gem 'fastcsv'
# Use MonetDB as the database backend
gem 'monetdb-sql', :git => "https://gitlab.c3sl.ufpr.br/simcaq/monetdb-sql.git"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
......
# 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/
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;
}
}
// Place all the styles related to the SchoolClasses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class SchoolClassesController < ApplicationController
before_action :set_school_class, only: [:show, :edit, :update, :destroy]
# GET /school_classes
# GET /school_classes.json
def index
@school_classes = SchoolClass.all
end
# GET /school_classes/1
# GET /school_classes/1.json
def show
end
# GET /school_classes/new
def new
@school_class = SchoolClass.new
end
# GET /school_classes/1/edit
def edit
end
# POST /school_classes
# POST /school_classes.json
def create
@school_class = SchoolClass.new(school_class_params)
respond_to do |format|
if @school_class.save
format.html { redirect_to @school_class, notice: 'School class was successfully created.' }
format.json { render :show, status: :created, location: @school_class }
else
format.html { render :new }
format.json { render json: @school_class.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /school_classes/1
# PATCH/PUT /school_classes/1.json
def update
respond_to do |format|
if @school_class.update(school_class_params)
format.html { redirect_to @school_class, notice: 'School class was successfully updated.' }
format.json { render :show, status: :ok, location: @school_class }
else
format.html { render :edit }
format.json { render json: @school_class.errors, status: :unprocessable_entity }
end
end
end
# DELETE /school_classes/1
# DELETE /school_classes/1.json
def destroy
@school_class.destroy
respond_to do |format|
format.html { redirect_to school_classes_url, notice: 'School class was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school_class
@school_class = SchoolClass.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def school_class_params
params.require(:school_class).permit(:census_year, :class_code, :num_enrollments, :location_id)
end
end
module SchoolClassesHelper
end
class AdministrativeLevel < ActiveRecord::Base
# associations
has_many :school_classes
# validations
validates_presence_of :name
end
class City < ActiveRecord::Base
# associations
has_many :school_classes
# validations
validates_presence_of :city_code,
:name
validates_uniqueness_of :city_code
end
class Location < ActiveRecord::Base
# associations
has_many :school_classes
# validations
validates_presence_of :name
end
class Region < ActiveRecord::Base
# associations
has_many :cities
# validations
validates_presence_of :name
end
class SchoolClass < ActiveRecord::Base
# associations
belongs_to :administrative_level
belongs_to :school_class_type
belongs_to :city
belongs_to :state
belongs_to :location
# validations
validates_presence_of :census_year,
:num_enrollments,
:administrative_level,
:city,
:state,
:location,
:school_class_type
validates_numericality_of :census_year,
only_integer: true,
greater_than: 0
end
class SchoolClassType < ActiveRecord::Base
# associations
has_many :school_classes
# validations
validates_presence_of :code,
:description
end
class State < ActiveRecord::Base
# associations
has_many :school_classes
belongs_to :region
# validations
validates_presence_of :name,
:region
end
<%= form_for(@school_class) do |f| %>
<% if @school_class.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@school_class.errors.count, "error") %> prohibited this school_class from being saved:</h2>
<ul>
<% @school_class.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :census_year %><br>
<%= f.number_field :census_year %>
</div>
<div class="field">
<%= f.label :class_code %><br>
<%= f.number_field :class_code %>
</div>
<div class="field">
<%= f.label :num_enrollments %><br>
<%= f.number_field :num_enrollments %>
</div>
<div class="field">
<%= f.label :location_id %><br>
<%= f.number_field :location_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing School Class</h1>
<%= render 'form' %>
<%= link_to 'Show', @school_class %> |
<%= link_to 'Back', school_classes_path %>
<p id="notice"><%= notice %></p>
<h1>Listing School Classes</h1>
<table>
<thead>
<tr>
<th>Census year</th>
<th>Class code</th>
<th>Num enrollments</th>
<th>Location</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @school_classes.each do |school_class| %>
<tr>
<td><%= school_class.census_year %></td>
<td><%= school_class.class_code %></td>
<td><%= school_class.num_enrollments %></td>
<td><%= school_class.location_id %></td>
<td><%= link_to 'Show', school_class %></td>
<td><%= link_to 'Edit', edit_school_class_path(school_class) %></td>
<td><%= link_to 'Destroy', school_class, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New School class', new_school_class_path %>
json.array!(@school_classes) do |school_class|
json.extract! school_class, :id, :census_year, :class_code, :num_enrollments, :location_id
json.url school_class_url(school_class, format: :json)
end
<h1>New School Class</h1>
<%= render 'form' %>
<%= link_to 'Back', school_classes_path %>
<p id="notice"><%= notice %></p>
<p>
<strong>Census year:</strong>
<%= @school_class.census_year %>
</p>
<p>
<strong>Class code:</strong>
<%= @school_class.class_code %>
</p>
<p>
<strong>Num enrollments:</strong>
<%= @school_class.num_enrollments %>
</p>
<p>
<strong>Location:</strong>
<%= @school_class.location_id %>
</p>
<%= link_to 'Edit', edit_school_class_path(@school_class) %> |
<%= link_to 'Back', school_classes_path %>
json.extract! @school_class, :id, :census_year, :class_code, :num_enrollments, :location_id, :created_at, :updated_at
Rails.application.routes.draw do
resources :school_classes
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
......
class CreateStates < ActiveRecord::Migration
def change
create_table :states do |t|
t.string :name
t.belongs_to :region, index: true
t.timestamps null: false
end
end
end
class CreateCities < ActiveRecord::Migration
def change
create_table :cities do |t|
t.string :city_code
t.string :name
t.timestamps null: false
end
end
end
class CreateRegions < ActiveRecord::Migration
def change
create_table :regions do |t|
t.string :name
t.timestamps null: false
end
end
end
class CreateAdministrativeLevels < ActiveRecord::Migration
def change
create_table :administrative_levels do |t|
t.string :name
t.timestamps null: false
end
end
end
class CreateLocations < ActiveRecord::Migration
def change
create_table :locations do |t|
t.string :name
t.timestamps null: false
end
end
end
class CreateSchoolClasses < ActiveRecord::Migration
def change
create_table :school_classes do |t|
t.integer :census_year
t.integer :num_enrollments
t.belongs_to :administrative_level, index: true
t.belongs_to :school_class_type, index: true
t.belongs_to :city, index: true
t.belongs_to :state, index: true
t.belongs_to :location, index: true
t.timestamps null: false
end
end
end
class CreateSchoolClassTypes < ActiveRecord::Migration
def change
create_table :school_class_types do |t|
t.integer :code
t.string :description
t.timestamps null: false
end
end
end
id;name
1;Federal
2;Estadual
3;Municipal
4;Privada
This diff is collapsed.
id;name
1;Urbana
2;Rural
id;name
1;Norte
2;Nordeste
3;Sudeste
4;Sul
5;Centro-Oeste
codigo;descricao
0;Não se aplica
1;Classe hospitalar
2;Unidade de atendimento socioeducativo
3;Unidade prisional
4;Atendimento complementar
5;Atendimento Educacional Especializado (AEE)
id;nome;fk_regiao_id
11;Rondônia;1
12;Acre;1
13;Amazonas;1
14;Roraima;1
15;Pará;1
16;Amapá;1
17;Tocantins;1
21;Maranhão;2
22;Piauí;2
23;Ceará;2
24;Rio Grande do Norte;2
25;Paraíba;2
26;Pernambuco;2
27;Alagoas;2
28;Sergipe;2
29;Bahia;2
31;Minas Gerais;3
32;Espírito Santo;3
33;Rio de Janeiro;3
35;São Paulo;3
41;Paraná;4
42;Santa Catarina;4
43;Rio Grande do Sul;4
50;Mato Grosso do Sul;5
51;Mato Grosso;5
52;Goiás;5
53;Distrito Federal;5
This diff is collapsed.
require 'test_helper'
class SchoolClassesControllerTest < ActionController::TestCase
setup do
@school_class = school_classes(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:school_classes)
end
test "should get new" do
get :new
assert_response :success
end
test "should create school_class" do
assert_difference('SchoolClass.count') do
post :create, school_class: { census_year: @school_class.census_year, class_code: @school_class.class_code, location_id: @school_class.location_id, num_enrollments: @school_class.num_enrollments }
end
assert_redirected_to school_class_path(assigns(:school_class))
end
test "should show school_class" do
get :show, id: @school_class
assert_response :success
end
test "should get edit" do
get :edit, id: @school_class
assert_response :success
end
test "should update school_class" do
patch :update, id: @school_class, school_class: { census_year: @school_class.census_year, class_code: @school_class.class_code, location_id: @school_class.location_id, num_enrollments: @school_class.num_enrollments }
assert_redirected_to school_class_path(assigns(:school_class))
end
test "should destroy school_class" do
assert_difference('SchoolClass.count', -1) do
delete :destroy, id: @school_class
end
assert_redirected_to school_classes_path
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
city_code: MyString
name: MyString
two:
city_code: MyString
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
id:
name: MyString
two:
id:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
code: 1
name: MyString
two:
code: 1
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
census_year: 1
class_code: 1
num_enrollments: 1
location_id: 1
two:
census_year: 1
class_code: 1
num_enrollments: 1
location_id: 1
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
state_id:
name: MyString
two:
state_id:
name: MyString
require 'test_helper'
class AdministrativeLevelTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class CityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class LocationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class RegionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class SchoolClassTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class SchoolClassTypeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class StateTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end