Cités et régions ajoutées

This commit is contained in:
echarp 2013-12-03 21:56:20 +01:00
parent db2f76c4cb
commit 107a34c1a0
35 changed files with 395 additions and 2 deletions

View File

@ -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/

View File

@ -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/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the cities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the regions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -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

View File

@ -0,0 +1,2 @@
class CitiesController < InheritedResources::Base
end

View File

@ -0,0 +1,2 @@
class RegionsController < InheritedResources::Base
end

View File

@ -0,0 +1,2 @@
module CitiesHelper
end

View File

@ -0,0 +1,2 @@
module RegionsHelper
end

2
app/models/city.rb Normal file
View File

@ -0,0 +1,2 @@
class City < ActiveRecord::Base
end

2
app/models/region.rb Normal file
View File

@ -0,0 +1,2 @@
class Region < ActiveRecord::Base
end

View File

@ -0,0 +1,31 @@
= form_for @city do |f|
- if @city.errors.any?
#error_explanation
%h2= "#{pluralize(@city.errors.count, "error")} prohibited this city from being saved:"
%ul
- @city.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.field
= f.label :majname
= f.text_field :majname
.field
= f.label :postalcode
= f.number_field :postalcode
.field
= f.label :inseecode
= f.number_field :inseecode
.field
= f.label :regioncode
= f.number_field :regioncode
.field
= f.label :latitude
= f.text_field :latitude
.field
= f.label :longitude
= f.text_field :longitude
.actions
= f.submit 'Save'

View File

@ -0,0 +1,7 @@
%h1 Editing city
= render 'form'
= link_to 'Show', @city
\|
= link_to 'Back', cities_path

View File

@ -0,0 +1,31 @@
%h1 Listing cities
%table
%tr
%th Name
%th Majname
%th Postalcode
%th Inseecode
%th Regioncode
%th Latitude
%th Longitude
%th
%th
%th
- @cities.each do |city|
%tr
%td= city.name
%td= city.majname
%td= city.postalcode
%td= city.inseecode
%td= city.regioncode
%td= city.latitude
%td= city.longitude
%td= link_to 'Show', city
%td= link_to 'Edit', edit_city_path(city)
%td= link_to 'Destroy', city, :method => :delete, :data => { :confirm => 'Are you sure?' }
%br
= link_to 'New City', new_city_path

View File

@ -0,0 +1,4 @@
json.array!(@cities) do |city|
json.extract! city, :name, :majname, :postalcode, :inseecode, :regioncode, :latitude, :longitude
json.url city_url(city, format: :json)
end

View File

@ -0,0 +1,5 @@
%h1 New city
= render 'form'
= link_to 'Back', cities_path

View File

@ -0,0 +1,27 @@
%p#notice= notice
%p
%b Name:
= @city.name
%p
%b Majname:
= @city.majname
%p
%b Postalcode:
= @city.postalcode
%p
%b Inseecode:
= @city.inseecode
%p
%b Regioncode:
= @city.regioncode
%p
%b Latitude:
= @city.latitude
%p
%b Longitude:
= @city.longitude
= link_to 'Edit', edit_city_path(@city)
\|
= link_to 'Back', cities_path

View File

@ -0,0 +1 @@
json.extract! @city, :name, :majname, :postalcode, :inseecode, :regioncode, :latitude, :longitude, :created_at, :updated_at

View File

@ -0,0 +1,13 @@
= form_for @region do |f|
- if @region.errors.any?
#error_explanation
%h2= "#{pluralize(@region.errors.count, "error")} prohibited this region from being saved:"
%ul
- @region.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.actions
= f.submit 'Save'

View File

@ -0,0 +1,7 @@
%h1 Editing region
= render 'form'
= link_to 'Show', @region
\|
= link_to 'Back', regions_path

View File

@ -0,0 +1,19 @@
%h1 Listing regions
%table
%tr
%th Name
%th
%th
%th
- @regions.each do |region|
%tr
%td= region.name
%td= link_to 'Show', region
%td= link_to 'Edit', edit_region_path(region)
%td= link_to 'Destroy', region, :method => :delete, :data => { :confirm => 'Are you sure?' }
%br
= link_to 'New Region', new_region_path

View File

@ -0,0 +1,4 @@
json.array!(@regions) do |region|
json.extract! region, :name
json.url region_url(region, format: :json)
end

View File

@ -0,0 +1,5 @@
%h1 New region
= render 'form'
= link_to 'Back', regions_path

View File

@ -0,0 +1,9 @@
%p#notice= notice
%p
%b Name:
= @region.name
= link_to 'Edit', edit_region_path(@region)
\|
= link_to 'Back', regions_path

View File

@ -0,0 +1 @@
json.extract! @region, :name, :created_at, :updated_at

View File

@ -5,7 +5,7 @@ ActiveAdmin.setup do |config|
# Set the title that is displayed on the main layout # Set the title that is displayed on the main layout
# for each of the active admin pages. # for each of the active admin pages.
# #
config.site_title = "Agenda Du Libre Rails" config.site_title = "Agenda Du Libre"
# Set the link url for the title. For example, to take # Set the link url for the title. For example, to take
# users to your main site. Defaults to no link. # users to your main site. Defaults to no link.

View File

@ -1,7 +1,10 @@
AgendaDuLibreRails::Application.routes.draw do AgendaDuLibreRails::Application.routes.draw do
resources :cities
resources :regions
resources :users
devise_for :admin_users, ActiveAdmin::Devise.config devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self) ActiveAdmin.routes(self)
resources :users
root to: 'users#index' root to: 'users#index'

View File

@ -0,0 +1,49 @@
require 'test_helper'
class CitiesControllerTest < ActionController::TestCase
setup do
@city = cities(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:cities)
end
test "should get new" do
get :new
assert_response :success
end
test "should create city" do
assert_difference('City.count') do
post :create, city: { inseecode: @city.inseecode, latitude: @city.latitude, longitude: @city.longitude, majname: @city.majname, name: @city.name, postalcode: @city.postalcode, regioncode: @city.regioncode }
end
assert_redirected_to city_path(assigns(:city))
end
test "should show city" do
get :show, id: @city
assert_response :success
end
test "should get edit" do
get :edit, id: @city
assert_response :success
end
test "should update city" do
patch :update, id: @city, city: { inseecode: @city.inseecode, latitude: @city.latitude, longitude: @city.longitude, majname: @city.majname, name: @city.name, postalcode: @city.postalcode, regioncode: @city.regioncode }
assert_redirected_to city_path(assigns(:city))
end
test "should destroy city" do
assert_difference('City.count', -1) do
delete :destroy, id: @city
end
assert_redirected_to cities_path
end
end

View File

@ -0,0 +1,49 @@
require 'test_helper'
class RegionsControllerTest < ActionController::TestCase
setup do
@region = regions(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:regions)
end
test "should get new" do
get :new
assert_response :success
end
test "should create region" do
assert_difference('Region.count') do
post :create, region: { name: @region.name }
end
assert_redirected_to region_path(assigns(:region))
end
test "should show region" do
get :show, id: @region
assert_response :success
end
test "should get edit" do
get :edit, id: @region
assert_response :success
end
test "should update region" do
patch :update, id: @region, region: { name: @region.name }
assert_redirected_to region_path(assigns(:region))
end
test "should destroy region" do
assert_difference('Region.count', -1) do
delete :destroy, id: @region
end
assert_redirected_to regions_path
end
end

19
test/fixtures/cities.yml vendored Normal file
View File

@ -0,0 +1,19 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
majname: MyString
postalcode: 1
inseecode: 1
regioncode: 1
latitude: 1.5
longitude: 1.5
two:
name: MyString
majname: MyString
postalcode: 1
inseecode: 1
regioncode: 1
latitude: 1.5
longitude: 1.5

7
test/fixtures/regions.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString

View File

@ -0,0 +1,4 @@
require 'test_helper'
class CitiesHelperTest < ActionView::TestCase
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class RegionsHelperTest < ActionView::TestCase
end

7
test/models/city_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class CityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class RegionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end