Skip to content

Commit

Permalink
Add TPS
Browse files Browse the repository at this point in the history
  • Loading branch information
fikriauliya committed Jul 12, 2014
1 parent 1cd2b2f commit 1565536
Show file tree
Hide file tree
Showing 18 changed files with 21,452 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
# Use jquery as the JavaScript li`brary
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/tps.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
14 changes: 14 additions & 0 deletions app/controllers/tps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class TpsController < ApplicationController
before_action :set_tp, only: [:show, :edit, :update, :destroy]

# GET /tps
# GET /tps.json
def index
@tps = Tps.all
end

# GET /tps/1
# GET /tps/1.json
def show
end
end
2 changes: 2 additions & 0 deletions app/helpers/tps_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TpsHelper
end
5 changes: 5 additions & 0 deletions app/models/tps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Tps < ActiveRecord::Base
def c1_url
return "http://scanc1.kpu.go.id/viewp.php?f=#{self.kelurahan_id}#{self.tps_id.rjust(3, '0')}04.jpg"
end
end
17 changes: 17 additions & 0 deletions app/views/tps/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%h1 Listing tps

%table
%tr
%th Desa
%th Kelurahan
%th Tps
%th
%th
%th

- @tps.each do |tp|
%tr
%td= tp.desa
%td= tp.kelurahan_id
%td= tp.tps_id
%td= link_to tp.c1_url, tp.c1_url
4 changes: 4 additions & 0 deletions app/views/tps/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.array!(@tps) do |tp|
json.extract! tp, :id, :desa, :kelurahan_id, :tps_id
json.url tp_url(tp, format: :json)
end
15 changes: 15 additions & 0 deletions app/views/tps/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%p#notice= notice

%p
%b Desa:
= @tp.desa
%p
%b Kelurahan:
= @tp.kelurahan_id
%p
%b Tps:
= @tp.tps_id

= link_to 'Edit', edit_tp_path(@tp)
\|
= link_to 'Back', tps_index_path
1 change: 1 addition & 0 deletions app/views/tps/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.extract! @tp, :id, :desa, :kelurahan_id, :tps_id, :created_at, :updated_at
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Rails.application.routes.draw do
resources :tps

get 'profiles/:id', :controller => 'profiles', :action => 'show'
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

Expand Down
21,278 changes: 21,278 additions & 0 deletions db/data

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions db/migrate/20140712050723_create_tps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateTps < ActiveRecord::Migration
def change
create_table :tps do |t|
t.string :desa
t.string :kelurahan_id
t.string :tps_id

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140626023500) do
ActiveRecord::Schema.define(version: 20140712050723) do

create_table "tps", force: true do |t|
t.string "desa"
t.string "kelurahan_id"
t.string "tps_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", force: true do |t|
t.string "email", default: "", null: false
Expand Down
19 changes: 19 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)


inserts = []

File.open("db/data", "r").each_line do |line|
desa = line[27..52].strip
kelurahan_id = line[53..59].strip
tps_id = line[60..63].strip
inserts.push("(\"#{desa}\", \"#{kelurahan_id}\" , \"#{tps_id}\")")
end

CONN = ActiveRecord::Base.connection

puts "Inserting TPS data"
slices = inserts.each_slice(100).to_a
slices.each do |slice|
sql = "INSERT INTO TPS('desa', 'kelurahan_id', 'tps_id') VALUES #{slice.join(',')}"
CONN.execute(sql)
end
49 changes: 49 additions & 0 deletions test/controllers/tps_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'test_helper'

class TpsControllerTest < ActionController::TestCase
setup do
@tp = tps(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:tps)
end

test "should get new" do
get :new
assert_response :success
end

test "should create tp" do
assert_difference('Tps.count') do
post :create, tp: { desa: @tp.desa, kelurahan_id: @tp.kelurahan_id, tps_id: @tp.tps_id }
end

assert_redirected_to tp_path(assigns(:tp))
end

test "should show tp" do
get :show, id: @tp
assert_response :success
end

test "should get edit" do
get :edit, id: @tp
assert_response :success
end

test "should update tp" do
patch :update, id: @tp, tp: { desa: @tp.desa, kelurahan_id: @tp.kelurahan_id, tps_id: @tp.tps_id }
assert_redirected_to tp_path(assigns(:tp))
end

test "should destroy tp" do
assert_difference('Tps.count', -1) do
delete :destroy, id: @tp
end

assert_redirected_to tps_index_path
end
end
11 changes: 11 additions & 0 deletions test/fixtures/tps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
desa: MyString
kelurahan_id: MyString
tps_id: MyString

two:
desa: MyString
kelurahan_id: MyString
tps_id: MyString
4 changes: 4 additions & 0 deletions test/helpers/tps_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class TpsHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/models/tps_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TpsTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 1565536

Please sign in to comment.