Renames Legislation model to LegacyLegislation

Renames the model and related stuff from Legislation 
to LegacyLegislation to avoid name clashes with 
the future Legislation module.
This commit is contained in:
Amaia Castro
2016-11-17 15:03:58 +01:00
parent 9e5a55be68
commit 9a9f1da5a0
17 changed files with 79 additions and 77 deletions

View File

@@ -24,7 +24,7 @@ class AnnotationsController < ApplicationController
end end
def search def search
@annotations = Annotation.where(legislation_id: params[:legislation_id]) @annotations = Annotation.where(legacy_legislation_id: params[:legacy_legislation_id])
annotations_hash = { total: @annotations.size, rows: @annotations } annotations_hash = { total: @annotations.size, rows: @annotations }
render json: annotations_hash.to_json(methods: :permissions) render json: annotations_hash.to_json(methods: :permissions)
end end
@@ -35,6 +35,6 @@ class AnnotationsController < ApplicationController
params params
.require(:annotation) .require(:annotation)
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
.merge(legislation_id: params[:legislation_id]) .merge(legacy_legislation_id: params[:legacy_legislation_id])
end end
end end

View File

@@ -0,0 +1,8 @@
class LegacyLegislationsController < ApplicationController
load_and_authorize_resource
def show
@legacy_legislation = LegacyLegislation.find(params[:id])
end
end

View File

@@ -1,8 +0,0 @@
class LegislationsController < ApplicationController
load_and_authorize_resource
def show
@legislation = Legislation.find(params[:id])
end
end

View File

@@ -7,7 +7,7 @@ module Abilities
can [:read, :map, :summary], Proposal can [:read, :map, :summary], Proposal
can :read, Comment can :read, Comment
can :read, SpendingProposal can :read, SpendingProposal
can :read, Legislation can :read, LegacyLegislation
can :read, User can :read, User
can [:search, :read], Annotation can [:search, :read], Annotation
can :new, DirectMessage can :new, DirectMessage

View File

@@ -1,7 +1,7 @@
class Annotation < ActiveRecord::Base class Annotation < ActiveRecord::Base
serialize :ranges, Array serialize :ranges, Array
belongs_to :legislation belongs_to :legacy_legislation
belongs_to :user belongs_to :user
def permissions def permissions

View File

@@ -0,0 +1,3 @@
class LegacyLegislation < ActiveRecord::Base
has_many :annotations
end

View File

@@ -1,3 +0,0 @@
class Legislation < ActiveRecord::Base
has_many :annotations
end

View File

@@ -0,0 +1,29 @@
<div class="row margin-top">
<div class="small-12 column">
<div class="float-right">
<a class="button warning" type="button" data-toggle="help-legacy-legislation">
<sub><span class="icon-edit"></span></sub>&nbsp;
<%= t("legacy_legislation.help.title") %>
</a>
<div class="dropdown-pane" id="help-legacy-legislation" data-dropdown data-auto-focus="true">
<p>
<%= t("legacy_legislation.help.text",
sign_in: link_to(t("legacy_legislation.help.text_sign_in"), new_user_session_path),
sign_up: link_to(t("legacy_legislation.help.text_sign_up"), new_user_registration_path)).html_safe %>
<%= image_tag ("annotator_help.gif"), alt: t("legacy_legislation.help.alt") %>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="small-12 medium-9 small-centered column">
<section data-annotatable-type="legacy_legislation"
data-annotatable-id="<%= @legacy_legislation.id %>">
<h1 class="text-center"><%= @legacy_legislation.title %></h1>
<div id="legacy_legislation_body"><%= @legacy_legislation.body %></div>
</section>
</div>
</div>

View File

@@ -1,29 +0,0 @@
<div class="row margin-top">
<div class="small-12 column">
<div class="float-right">
<a class="button warning" type="button" data-toggle="help-legislation">
<sub><span class="icon-edit"></span></sub>&nbsp;
<%= t("legislation.help.title") %>
</a>
<div class="dropdown-pane" id="help-legislation" data-dropdown data-auto-focus="true">
<p>
<%= t("legislation.help.text",
sign_in: link_to(t("legislation.help.text_sign_in"), new_user_session_path),
sign_up: link_to(t("legislation.help.text_sign_up"), new_user_registration_path)).html_safe %>
<%= image_tag ("annotator_help.gif"), alt: t("legislation.help.alt") %>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="small-12 medium-9 small-centered column">
<section data-annotatable-type="legislation"
data-annotatable-id="<%= @legislation.id %>">
<h1 class="text-center"><%= @legislation.title %></h1>
<div id="legislation_body"><%= @legislation.body %></div>
</section>
</div>
</div>

View File

@@ -212,7 +212,7 @@ en:
proposal_ballot: Voting proposal_ballot: Voting
see_all: See proposals see_all: See proposals
spending_proposals: Spending proposals spending_proposals: Spending proposals
legislation: legacy_legislation:
help: help:
alt: Select the text you want to comment and press the button with the pencil. alt: Select the text you want to comment and press the button with the pencil.
text: To comment this document you must %{sign_in} or %{sign_up}. Then select the text you want to comment and press the button with the pencil. text: To comment this document you must %{sign_in} or %{sign_up}. Then select the text you want to comment and press the button with the pencil.

View File

@@ -212,7 +212,7 @@ es:
proposal_ballot: Votaciones proposal_ballot: Votaciones
see_all: Ver propuestas see_all: Ver propuestas
spending_proposals: Presupuestos ciudadanos spending_proposals: Presupuestos ciudadanos
legislation: legacy_legislation:
help: help:
alt: Selecciona el texto que quieres comentar y pulsa en el botón con el lápiz. alt: Selecciona el texto que quieres comentar y pulsa en el botón con el lápiz.
text: Para comentar este documento debes %{sign_in} o %{sign_up}. Después selecciona el texto que quieres comentar y pulsa en el botón con el lápiz. text: Para comentar este documento debes %{sign_in} o %{sign_up}. Después selecciona el texto que quieres comentar y pulsa en el botón con el lápiz.

View File

@@ -79,7 +79,7 @@ Rails.application.routes.draw do
resources :stats, only: [:index] resources :stats, only: [:index]
resources :legislations, only: [:show] resources :legacy_legislations, only: [:show], path: 'legislations'
resources :annotations do resources :annotations do
get :search, on: :collection get :search, on: :collection

View File

@@ -316,10 +316,6 @@ puts "Creating Valuation Assignments"
SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator
end end
puts "Creating Legislation"
Legislation.create!(title: 'Participatory Democracy', body: 'In order to achieve...')
puts "Ignoring flags in Debates, comments & proposals" puts "Ignoring flags in Debates, comments & proposals"

View File

@@ -0,0 +1,6 @@
class RenameLegislationsToLegacyLegislations < ActiveRecord::Migration
def change
rename_table :legislations, :legacy_legislations
rename_column :annotations, :legislation_id, :legacy_legislation_id
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161102133838) do ActiveRecord::Schema.define(version: 20161117115841) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -57,10 +57,10 @@ ActiveRecord::Schema.define(version: 20161102133838) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "user_id" t.integer "user_id"
t.integer "legislation_id" t.integer "legacy_legislation_id"
end end
add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree add_index "annotations", ["legacy_legislation_id"], name: "index_annotations_on_legacy_legislation_id", using: :btree
add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
create_table "banners", force: :cascade do |t| create_table "banners", force: :cascade do |t|
@@ -221,7 +221,7 @@ ActiveRecord::Schema.define(version: 20161102133838) do
add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree
create_table "legislations", force: :cascade do |t| create_table "legacy_legislations", force: :cascade do |t|
t.string "title" t.string "title"
t.text "body" t.text "body"
t.datetime "created_at", null: false t.datetime "created_at", null: false
@@ -550,7 +550,7 @@ ActiveRecord::Schema.define(version: 20161102133838) do
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
add_foreign_key "administrators", "users" add_foreign_key "administrators", "users"
add_foreign_key "annotations", "legislations" add_foreign_key "annotations", "legacy_legislations"
add_foreign_key "annotations", "users" add_foreign_key "annotations", "users"
add_foreign_key "failed_census_calls", "users" add_foreign_key "failed_census_calls", "users"
add_foreign_key "flags", "users" add_foreign_key "flags", "users"

View File

@@ -234,8 +234,8 @@ FactoryGirl.define do
end end
end end
factory :legislation do factory :legacy_legislation do
sequence(:title) { |n| "Legislation #{n}" } sequence(:title) { |n| "Legacy Legislation #{n}" }
body "In order to achieve this..." body "In order to achieve this..."
end end
@@ -243,7 +243,7 @@ FactoryGirl.define do
quote "ipsum" quote "ipsum"
text "Loremp ipsum dolor" text "Loremp ipsum dolor"
ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}] ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]
legislation legacy_legislation
user user
end end

View File

@@ -1,11 +1,11 @@
require 'rails_helper' require 'rails_helper'
feature 'Legislation' do feature 'Legacy Legislation' do
scenario 'Show' do scenario 'Show' do
legislation = create(:legislation, title: 'Change the world', body: 'To achieve this...') legacy_legislation = create(:legacy_legislation, title: 'Change the world', body: 'To achieve this...')
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
expect(page).to have_content 'Change the world' expect(page).to have_content 'Change the world'
expect(page).to have_content 'To achieve this...' expect(page).to have_content 'To achieve this...'
@@ -17,11 +17,11 @@ feature 'Legislation' do
background { login_as user } background { login_as user }
scenario 'Create' do scenario 'Create' do
legislation = create(:legislation) legacy_legislation = create(:legacy_legislation)
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
page.find(:css, "#legislation_body").double_click page.find(:css, "#legacy_legislation_body").double_click
page.find(:css, ".annotator-adder button").click page.find(:css, ".annotator-adder button").click
fill_in 'annotator-field-0', with: 'this is my annotation' fill_in 'annotator-field-0', with: 'this is my annotation'
page.find(:css, ".annotator-controls a[href='#save']").click page.find(:css, ".annotator-controls a[href='#save']").click
@@ -30,7 +30,7 @@ feature 'Legislation' do
first(:css, ".annotator-hl").click first(:css, ".annotator-hl").click
expect(page).to have_content "this is my annotation" expect(page).to have_content "this is my annotation"
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
expect(page).to have_css ".annotator-hl" expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click first(:css, ".annotator-hl").click
@@ -38,10 +38,10 @@ feature 'Legislation' do
end end
scenario 'Update' do scenario 'Update' do
legislation = create(:legislation) legacy_legislation = create(:legacy_legislation)
annotation = create(:annotation, legislation: legislation, user: user, text: "my annotation") annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user, text: "my annotation")
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
expect(page).to have_css ".annotator-hl" expect(page).to have_css ".annotator-hl"
page.find(:css, ".annotator-hl").click page.find(:css, ".annotator-hl").click
@@ -55,17 +55,17 @@ feature 'Legislation' do
page.find(:css, ".annotator-hl").click page.find(:css, ".annotator-hl").click
expect(page).to have_content "edited annotation" expect(page).to have_content "edited annotation"
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
page.find(:css, ".annotator-hl").click page.find(:css, ".annotator-hl").click
expect(page).to have_content "edited annotation" expect(page).to have_content "edited annotation"
end end
scenario 'Destroy' do scenario 'Destroy' do
legislation = create(:legislation) legacy_legislation = create(:legacy_legislation)
annotation = create(:annotation, legislation: legislation, user: user) annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user)
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
expect(page).to have_css ".annotator-hl" expect(page).to have_css ".annotator-hl"
@@ -76,11 +76,11 @@ feature 'Legislation' do
end end
scenario 'Search' do scenario 'Search' do
legislation = create(:legislation) legacy_legislation = create(:legacy_legislation)
annotation1 = create(:annotation, legislation: legislation, text: "my annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]) annotation1 = create(:annotation, legacy_legislation: legacy_legislation, text: "my annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}])
annotation2 = create(:annotation, legislation: legislation, text: "my other annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>12, "end"=>"/div[1]", "endOffset"=>19}]) annotation2 = create(:annotation, legacy_legislation: legacy_legislation, text: "my other annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>12, "end"=>"/div[1]", "endOffset"=>19}])
visit legislation_path(legislation) visit legacy_legislation_path(legacy_legislation)
expect(page).to have_css ".annotator-hl" expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click first(:css, ".annotator-hl").click