The foreign key to table region is renamed to region_id

This commit is contained in:
echarp 2015-02-15 15:50:47 +01:00
parent 510d2c810d
commit c9ed8b2980
24 changed files with 153 additions and 128 deletions

View File

@ -6,7 +6,7 @@ ActiveAdmin.register Lug do
column :url
column :city
column :department
column :related_region
column :region
actions
end
@ -18,7 +18,7 @@ ActiveAdmin.register Lug do
end
row :city
row :department
row :related_region
row :region
end
active_admin_comments
end
@ -29,7 +29,7 @@ ActiveAdmin.register Lug do
f.input :url
f.input :city
f.input :department
f.input :related_region
f.input :region
end
f.actions
end

View File

@ -15,8 +15,8 @@ class EventsController < ApplicationController
respond_to do |format|
format.html { render layout: 'iframe' if params[:iframe] }
format.rss { @events = @events.future }
format.ics { @events = @events.last_year.includes :related_region }
format.xml { @events = @events.includes :related_region }
format.ics { @events = @events.last_year.includes :region }
format.xml { @events = @events.includes :region }
end
end
@ -109,8 +109,8 @@ class EventsController < ApplicationController
def event_params
params.require(:event)
.permit :lock_version, :title, :start_time, :end_time, :description,
:address, :city, :region, :locality, :url, :contact, :submitter,
:tags
:address, :city, :region_id, :locality, :url, :contact,
:submitter, :tags
end
# Check that you can only edit an existing event if you know its secret

View File

@ -69,8 +69,8 @@ class ModerationsController < ApplicationController
def moderation_params
params.require(:event)
.permit :lock_version, :title, :start_time, :end_time, :description,
:address, :city, :region, :locality, :url, :contact, :submitter,
:tags
:address, :city, :region_id, :locality, :url, :contact,
:submitter, :tags
end
# Useful to manage absolute url in mails

View File

@ -10,7 +10,7 @@ class StatsController < ApplicationController
end
def set_local
@regions = Event.joins(:related_region).group(:region, year_grouping).count
@regions = Event.joins(:region).group(:region, year_grouping).count
@city_events = Event.group(:city).having('count(city) > 3')
.order('count(city) desc').count
end

View File

@ -18,7 +18,7 @@ module EventsHelper
DC: { title: @event.title, date: @event.start_time.to_s },
geo: {
placename: @event.city,
region: @event.related_region,
region: @event.region,
position: "#{@event.latitude};#{@event.longitude}",
ICBM: "#{@event.latitude}, #{@event.longitude}"
}

View File

@ -5,10 +5,10 @@ module LugsHelper
description: @lug.url,
DC: { title: @lug.name },
geo: {
region: @lug.related_region,
region: @lug.region,
placename: @lug.city,
position: "#{@lug.related_city.try :latitude};" \
+ "#{@lug.related_city.try :longitude}"
position: "#{@lug.city.try :latitude};" \
+ "#{@lug.city.try :longitude}"
}
end
end

View File

@ -5,16 +5,14 @@ class Event < ActiveRecord::Base
extend SimpleCalendar
strip_attributes
belongs_to :related_region, foreign_key: 'region', class_name: Region
belongs_to :region
has_many :notes, dependent: :destroy
has_one :related_city, foreign_key: :name, primary_key: :city,
class_name: City
validates :title, presence: true
validate :end_after_start
validates :description, presence: true
validates :city, presence: true
validates :related_region, presence: true
validates :region, presence: true
validates :url, presence: true, format: %r{\Ahttps?:\/\/.*\..*\z}
validates :contact, email: true
validates :submitter, email: true
@ -92,7 +90,7 @@ class Event < ActiveRecord::Base
end
def full_address
[address, city, related_region.try(:name)].compact.join ', '
[address, city, region.try(:name)].compact.join ', '
end
def hashtags

View File

@ -1,6 +1,4 @@
# Groups related to this agenda
class Lug < ActiveRecord::Base
belongs_to :related_region, foreign_key: 'region', class_name: Region
has_one :related_city, foreign_key: :name, primary_key: :city,
class_name: City
belongs_to :region
end

View File

@ -1,7 +1,7 @@
# This is mostly to group events around a region
class Region < ActiveRecord::Base
has_many :lugs, foreign_key: :region
has_many :events, foreign_key: :region
has_many :lugs
has_many :events
default_scope { order :name }

View File

@ -43,9 +43,9 @@
%option= city
.field.region
= f.label :region
= f.select :region,
= f.select :region_id,
options_from_collection_for_select(Region.all, 'id', 'name',
@event.region)
@event.region_id)
.field.locality
= f.label :locality
= f.select :locality,

View File

@ -8,7 +8,7 @@ xml.events do
xml.tag! 'end-time', event.end_time.strftime('%Y/%m/%d %T')
xml.address event.address
xml.city event.city
xml.region event.related_region
xml.region event.region
xml.locality event.locality
xml.tags event.tags
xml.contact event.contact

View File

@ -10,13 +10,13 @@
- if controller.controller_name == 'events' && controller.action_name == 'show'
%aside#lug-list
- if @event.related_region.lugs.present?
- if @event.region.present? && @event.region.lugs.present?
%h1
%em.fa.fa-users
= t '.lug-list'
- if @event.related_region
- if @event.region
%ul
- @event.related_region.lugs.order(department: :asc).each do |lug|
- @event.region.lugs.order(department: :asc).each do |lug|
%li
= link_to lug.name, lug
(#{lug.department})
@ -63,8 +63,8 @@
%span= @event.address
%span= link_to @event.city,
"http://fr.wikipedia.org/wiki/#{url_encode @event.city}"
%span= link_to @event.related_region.try(:name),
"http://fr.wikipedia.org/wiki/#{url_encode @event.related_region.try :name}"
%span= link_to @event.region.try(:name),
"http://fr.wikipedia.org/wiki/#{url_encode @event.region.try :name}"
- if @event.latitude && @event.longitude
.event#map{ data: { url: "#{maps_path format: :json}",

View File

@ -4,7 +4,7 @@
#{Event.human_attribute_name(:end_time).concat(':').ljust 12 } #{l @event.end_time, format: :at}
#{Event.human_attribute_name(:address).concat(':').ljust 12 } #{@event.address}
#{Event.human_attribute_name(:city).concat(':').ljust 12 } #{@event.city}
#{Event.human_attribute_name(:region).concat(':').ljust 12 } #{@event.related_region}
#{Event.human_attribute_name(:region).concat(':').ljust 12 } #{@event.region}
#{Event.human_attribute_name(:locality).concat(':').ljust 12 } #{t "attributes.locality_#{@event.locality}"}
#{Event.human_attribute_name(:url).concat(':').ljust 12 } #{@event.url}
#{Event.human_attribute_name(:contact).concat(':').ljust 12 } #{@event.contact}

View File

@ -1,7 +1,7 @@
= search_form_for @search || Lug.search(params[:q]) do |f|
= f.label :search, t('.label')
%em.fa.fa-users
= f.search_field :name_or_city_or_department_or_related_region_name_or_url_cont,
= f.search_field :name_or_city_or_department_or_region_name_or_url_cont,
id: :q_search, size: 16,
placeholder: t('.title', entity: Lug.model_name.human)
= f.button class: :search do

View File

@ -9,7 +9,7 @@
%th= sort_link @search, :name
%th= sort_link @search, :city
%th= sort_link @search, :department
%th= sort_link @search, :related_region_name, Lug.human_attribute_name(:related_region)
%th= sort_link @search, :region_name, Lug.human_attribute_name(:region)
%th= sort_link @search, :url
%th/
@ -18,17 +18,19 @@
%tr
%td
- if lug.url =~ /^http/
= image_tag lug.url+'/favicon.ico', alt: '', class: :favicon
= image_tag lug.url + '/favicon.ico', alt: '', class: :favicon
= lug.name
%td
= lug.city
%td
= lug.department
%td
= lug.related_region
= lug.region
%td
= link_to lug.url, lug.url
%td
= link_to t('show'), lug_path(lug, q: params[:q], page: params[:page]), class: :view_link
= link_to t('show'),
lug_path(lug, q: params[:q], page: params[:page]),
class: :view_link
= paginate @lugs

View File

@ -3,7 +3,7 @@
= render 'search'
%h2
= image_tag @lug.url+'/favicon.ico', alt: '', class: :favicon
= image_tag @lug.url + '/favicon.ico', alt: '', class: :favicon
= title @lug.name
%nav
@ -38,9 +38,9 @@
- if @lug.department.present?
%dt= Lug.human_attribute_name :department
%dd= @lug.department
- if @lug.related_region.present?
- if @lug.region.present?
%dt= Lug.human_attribute_name :region
%dd= @lug.related_region
%dd= @lug.region
- if @lug.url.present?
%dt= Lug.human_attribute_name :url
%dd= link_to @lug.url, @lug.url
@ -55,7 +55,7 @@
= Event.model_name.human.pluralize
- if @events_future.any?
%h3=raw t 'future', count: @events_future.count
%h3= raw t 'future', count: @events_future.count
%ul.fa-ul
- @events_future.order('start_time asc').each do |event|
%li
@ -69,7 +69,7 @@
.date= display_date event
- if @events_past.any?
%h3=raw t 'past', count: @events_past.count
%h3= raw t 'past', count: @events_past.count
%ul.fa-ul
- @events_past.order('start_time desc').each do |event|
%li
@ -82,4 +82,4 @@
= event.title
.date= display_date event
#map.events(data-url="#{maps_path format: :json, tag: @lug.name}")
.events#map(data-url="#{ maps_path format: :json, tag: @lug.name }")

View File

@ -16,7 +16,7 @@
%th= Event.human_attribute_name :city
%th= Event.human_attribute_name :region
%th= Event.human_attribute_name :submission_time
%th=t '.actions'
%th= t '.actions'
%tbody
- @events.each do |event|
@ -24,40 +24,40 @@
%td= event.title
%td= display_date event
%td= event.city
%td= event.related_region.name
%td= event.region.name
%td= time_ago_in_words event.submission_time
%th.actions
= link_to edit_moderation_path event do
%em.fa.fa-pencil
=t 'edit'
= t 'edit'
\-
= link_to validate_moderation_path event do
%em.fa.fa-thumbs-up
=t 'validate'
= t 'validate'
\-
= link_to refuse_moderation_path event do
%em.fa.fa-thumbs-down
=t 'refuse'
= t 'refuse'
\-
= link_to new_moderation_note_path event, envoiParMail: :oui do
%em.fa.fa-bullhorn
=t '.askInfos'
= t '.askInfos'
\-
= link_to new_moderation_note_path event do
%em.fa.fa-paperclip
=t '.createNote'
= t '.createNote'
- event.notes.each do |note|
%tr
%td.empty/
%td.note(colspan="5")
=raw note.contents
= raw note.contents
%em.author
=t '.posted_by',
= t '.posted_by',
author: "#{note.author.firstname} #{note.author.lastname}",
date: l(note.date, format: :at) rescue nil
.logout
= link_to destroy_user_session_path, method: :delete do
%em.fa.fa-sign-out
=t 'logout'
= t 'logout'

View File

@ -0,0 +1,7 @@
# The foreign key from event and lug to region was badly named
class RenameRegionForeignKey < ActiveRecord::Migration
def change
rename_column :events, :region, :region_id
rename_column :lugs, :region, :region_id
end
end

View File

@ -12,44 +12,44 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141011100700) do
ActiveRecord::Schema.define(version: 20150215121248) do
create_table "active_admin_comments", force: true do |t|
t.string "namespace"
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace", limit: 255
t.text "body"
t.string "resource_id", null: false
t.string "resource_type", null: false
t.string "resource_id", limit: 255, null: false
t.string "resource_type", limit: 255, null: false
t.integer "author_id"
t.string "author_type"
t.string "author_type", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
create_table "admin_users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
create_table "admin_users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
create_table "cities", force: true do |t|
t.string "name", default: "", null: false
t.string "majname", default: "", null: false
create_table "cities", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
t.string "majname", limit: 255, default: "", null: false
t.integer "postalcode"
t.integer "inseecode"
t.integer "regioncode"
@ -57,67 +57,87 @@ ActiveRecord::Schema.define(version: 20141011100700) do
t.float "longitude", limit: 24
end
add_index "cities", ["name"], name: "cities_name", using: :btree
add_index "cities", ["name"], name: "cities_name"
create_table "events", force: true do |t|
t.string "title", default: "", null: false
create_table "events", force: :cascade do |t|
t.string "title", limit: 255, default: "", null: false
t.text "description", null: false
t.datetime "start_time", null: false
t.datetime "end_time", null: false
t.string "city", default: "", null: false
t.integer "region", default: 0, null: false
t.string "city", limit: 255, default: "", null: false
t.integer "region_id", default: 0, null: false
t.integer "locality", default: 0, null: false
t.string "url", default: "", null: false
t.string "contact", default: "", null: false
t.string "submitter", default: "", null: false
t.string "url", limit: 255, default: "", null: false
t.string "contact", limit: 255, default: "", null: false
t.string "submitter", limit: 255, default: "", null: false
t.integer "moderated", default: 0, null: false
t.string "tags", default: "", null: false
t.string "secret", default: "", null: false
t.datetime "decision_time"
t.datetime "submission_time"
t.string "tags", limit: 255, default: "", null: false
t.string "secret", limit: 255, default: "", null: false
t.datetime "decision_time", null: false
t.datetime "submission_time", null: false
t.string "moderator_mail_id", limit: 32
t.string "submitter_mail_id", limit: 32
t.text "address"
t.float "latitude", limit: 24
t.float "longitude", limit: 24
t.float "latitude"
t.float "longitude"
t.integer "lock_version", default: 0, null: false
end
add_index "events", ["start_time", "end_time"], name: "events_date", using: :btree
add_index "events", ["start_time", "end_time"], name: "events_date"
create_table "lugs", force: true do |t|
t.integer "region", default: 0, null: false
create_table "lugs", force: :cascade do |t|
t.integer "region_id", default: 0, null: false
t.integer "department", default: 0, null: false
t.string "name", default: "", null: false
t.string "url", default: "", null: false
t.string "city", default: "", null: false
t.string "name", limit: 255, default: "", null: false
t.string "url", limit: 255, default: "", null: false
t.string "city", limit: 255, default: "", null: false
end
create_table "notes", force: true do |t|
create_table "notes", force: :cascade do |t|
t.text "contents", null: false
t.datetime "date", null: false
t.integer "event_id"
t.integer "author_id"
end
create_table "regions", force: true do |t|
t.string "name", default: "", null: false
create_table "regions", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
end
create_table "translations", force: true do |t|
t.string "locale"
t.string "key"
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type", limit: 255
t.integer "tagger_id"
t.string "tagger_type", limit: 255
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", force: :cascade do |t|
t.string "name", limit: 255
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "translations", force: :cascade do |t|
t.string "locale", limit: 255
t.string "key", limit: 255
t.text "value"
t.text "interpolations"
t.boolean "is_proc", default: false
end
create_table "users", force: true do |t|
t.string "login", default: "", null: false
t.string "password", default: "", null: false
t.string "email", default: "", null: false
t.string "lastname", default: "", null: false
t.string "firstname", default: "", null: false
create_table "users", force: :cascade do |t|
t.string "login", limit: 255, default: "", null: false
t.string "password", limit: 255, default: "", null: false
t.string "email", limit: 255, default: "", null: false
t.string "lastname", limit: 255, default: "", null: false
t.string "firstname", limit: 255, default: "", null: false
end
end

View File

@ -25,7 +25,7 @@ class EventsControllerTest < ActionController::TestCase
title: @event.title,
start_time: @event.start_time, end_time: @event.end_time,
description: @event.description,
city: @event.city, region: @event.related_region,
city: @event.city, region_id: @event.region.id,
url: @event.url,
contact: @event.contact,
tags: @event.tags
@ -43,7 +43,7 @@ class EventsControllerTest < ActionController::TestCase
title: @event.title,
start_time: @event.start_time, end_time: @event.end_time,
description: @event.description,
city: @event.city, region: @event.related_region,
city: @event.city, region_id: @event.region.id,
url: @event.url,
contact: @event.contact,
tags: @event.tags

View File

@ -20,14 +20,14 @@ class ModerationsControllerTest < ActionController::TestCase
test 'should preview event' do
patch :preview, id: @moderation, event: {
title: 'hello world',
related_region: regions(:region_one)
region: regions(:region_one)
}
end
test 'should edit event' do
put :update, id: @moderation, event: {
title: 'hello world',
related_region: regions(:region_one)
region: regions(:region_one)
}
assert_redirected_to :moderations
end

View File

@ -6,7 +6,7 @@ one:
start_time: <%= 2.hours.from_now %>
end_time: <%= 3.hours.from_now %>
city: city_one.name
related_region: region_one
region: region_one
locality: 1
url: http://exemple.com
contact: test@example.com
@ -26,7 +26,7 @@ two:
start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 17:04:56
city: city_two.name
related_region: region_two
region: region_two
locality: 1
url: http://exemple.com
contact: test2@example.com
@ -46,7 +46,7 @@ proposed:
start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 17:04:56
city: city_two.name
related_region: region_two
region: region_two
locality: 1
url: http://exemple.com
contact: test2@example.com

View File

@ -1,14 +1,14 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
related_region: region_one
region: region_one
city: Jolie ville
department: 1
name: MyString
url: MyString
two:
related_region: region_two
region: region_two
city: Jolie ville
department: 1
name: MyString

View File

@ -13,7 +13,7 @@ class EventTest < ActiveSupport::TestCase
end_time: Time.new + 1.hour,
description: 'et hop!',
city: City.first,
related_region: Region.first,
region: Region.first,
url: 'http://example.com',
contact: 'contact@example.com',
submitter: 'submitter@example.com',
@ -33,7 +33,7 @@ class EventTest < ActiveSupport::TestCase
end_time: Time.new + 1.hour,
description: 'et hop!',
city: City.first,
related_region: Region.first,
region: Region.first,
url: 'http://example.com',
contact: 'contact@example.com',
tags: 'hello world'
@ -63,7 +63,7 @@ class EventTest < ActiveSupport::TestCase
end_time: Time.new + 1.hour,
description: 'et hop!',
city: City.first,
related_region: Region.first,
region: Region.first,
url: 'http://example.com',
contact: 'contact@example.com',
tags: 'hello world'
@ -114,7 +114,7 @@ class EventTest < ActiveSupport::TestCase
test 'full address' do
@event.address = 'hello'
@event.city = 'world'
@event.related_region.name = 'all'
@event.region.name = 'all'
assert_equal 'hello, world, all', @event.full_address
end
end