diff --git a/app/assets/images/map.jpg b/app/assets/images/map.jpg
new file mode 100644
index 000000000..42abdca21
Binary files /dev/null and b/app/assets/images/map.jpg differ
diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss
index a98e8f256..586628556 100644
--- a/app/assets/stylesheets/layout.scss
+++ b/app/assets/stylesheets/layout.scss
@@ -623,19 +623,28 @@ footer {
}
}
-.tag-cloud {
+.categories {
- h3 {
- border-top: 2px solid $brand;
+ a {
+ background: $highlight;
+ border-radius: rem-calc(6);
display: inline-block;
- font-family: $font-family-sans-serif;
- font-size: rem-calc(16);
- margin: -1px 0 rem-calc(12);
- padding-top: $line-height/4;
- text-transform: uppercase;
+ font-size: $small-font-size;
+ margin-bottom: $line-height/3;
+ padding: $line-height/4 $line-height/3;
+ text-decoration: none;
}
}
+h3.sidebar-title {
+ border-top: 2px solid $brand;
+ display: inline-block;
+ font-size: rem-calc(16);
+ margin: -1px 0 rem-calc(12);
+ padding-top: $line-height/4;
+ text-transform: uppercase;
+}
+
// 05. Auth pages
// - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/app/assets/stylesheets/print.css b/app/assets/stylesheets/print.css
index ef76f607e..5297826c8 100644
--- a/app/assets/stylesheets/print.css
+++ b/app/assets/stylesheets/print.css
@@ -28,6 +28,8 @@ img.left { display: none !important; }
li.name { display: none !important; }
+li.kind { display: none !important; }
+
p.proposal-info span:nth-child(3) { display: none !important; }
.top-links { display: none !important; }
diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb
index fef6ab554..e46ba7da4 100644
--- a/app/controllers/concerns/commentable_actions.rb
+++ b/app/controllers/concerns/commentable_actions.rb
@@ -25,8 +25,8 @@ module CommentableActions
def new
@resource = resource_model.new
+ set_geozone
set_resource_instance
- load_featured_tags
end
def create
@@ -38,14 +38,14 @@ module CommentableActions
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
else
- load_featured_tags
+ load_categories
+ load_geozones
set_resource_instance
render :new
end
end
def edit
- load_featured_tags
end
def update
@@ -53,12 +53,19 @@ module CommentableActions
if resource.save_with_captcha
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
else
- load_featured_tags
+ load_categories
+ load_geozones
set_resource_instance
render :edit
end
end
+
+ def map
+ @resource = resource_model.new
+ @tag_cloud = tag_cloud
+ end
+
private
def track_event
@@ -69,8 +76,16 @@ module CommentableActions
resource_model.last_week.tag_counts.order("#{resource_name.pluralize}_count": :desc, name: :asc).limit(5)
end
- def load_featured_tags
- @featured_tags = ActsAsTaggableOn::Tag.where(featured: true)
+ def load_geozones
+ @geozones = Geozone.all.order(name: :asc)
+ end
+
+ def set_geozone
+ @resource.geozone = Geozone.find(params[resource_name.to_sym].try(:[], :geozone_id)) if params[resource_name.to_sym].try(:[], :geozone_id).present?
+ end
+
+ def load_categories
+ @categories = ActsAsTaggableOn::Tag.where("kind = 'category'").order(:name)
end
def parse_tag_filter
@@ -112,10 +127,6 @@ module CommentableActions
end
end
- def method_name
-
- end
-
def search_finish_date
params[:advanced_search][:date_max].try(:to_date) || Date.today
end
diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb
index a3e6e4a7f..ae8aa6f2a 100644
--- a/app/controllers/debates_controller.rb
+++ b/app/controllers/debates_controller.rb
@@ -7,7 +7,7 @@ class DebatesController < ApplicationController
before_action :parse_advanced_search_terms, only: :index
before_action :parse_tag_filter, only: :index
before_action :set_search_order, only: :index
- before_action :authenticate_user!, except: [:index, :show]
+ before_action :authenticate_user!, except: [:index, :show, :map]
feature_flag :debates
diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb
index 4d96af093..b80864bba 100644
--- a/app/controllers/management/proposals_controller.rb
+++ b/app/controllers/management/proposals_controller.rb
@@ -5,6 +5,8 @@ class Management::ProposalsController < Management::BaseController
before_action :check_verified_user, except: :print
before_action :set_proposal, only: [:vote, :show]
before_action :parse_search_terms, only: :index
+ before_action :load_categories, only: [:new, :edit]
+ before_action :load_geozones, only: [:edit]
has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print]
has_orders %w{most_voted newest}, only: :show
@@ -43,7 +45,7 @@ class Management::ProposalsController < Management::BaseController
managed_user
end
- ### Duplicated in application_controller. Move to a concenrn.
+ ### Duplicated in application_controller. Move to a concern.
def set_proposal_votes(proposals)
@proposal_votes = current_user ? current_user.proposal_votes(proposals) : {}
end
diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb
index c60d7cc43..1ee319b93 100644
--- a/app/controllers/proposals_controller.rb
+++ b/app/controllers/proposals_controller.rb
@@ -6,7 +6,9 @@ class ProposalsController < ApplicationController
before_action :parse_advanced_search_terms, only: :index
before_action :parse_tag_filter, only: :index
before_action :set_search_order, only: :index
- before_action :authenticate_user!, except: [:index, :show]
+ before_action :load_categories, only: [:index, :new, :edit, :map]
+ before_action :load_geozones, only: [:edit, :map]
+ before_action :authenticate_user!, except: [:index, :show, :map]
has_orders %w{hot_score confidence_score created_at relevance}, only: :index
has_orders %w{most_voted newest oldest}, only: :show
@@ -35,7 +37,7 @@ class ProposalsController < ApplicationController
private
def proposal_params
- params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key)
+ params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key, :geozone_id)
end
def resource_model
diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb
index 377ef7440..4de272b8c 100644
--- a/app/models/abilities/everyone.rb
+++ b/app/models/abilities/everyone.rb
@@ -3,8 +3,8 @@ module Abilities
include CanCan::Ability
def initialize(user)
- can :read, Debate
- can :read, Proposal
+ can [:read, :map], Debate
+ can [:read, :map], Proposal
can :read, Comment
can :read, SpendingProposal
can :read, Legislation
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 6e8392443..11617319b 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -14,6 +14,7 @@ class Debate < ActiveRecord::Base
include ActsAsParanoidAliases
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
+ belongs_to :geozone
has_many :comments, as: :commentable
validates :title, presence: true
diff --git a/app/models/proposal.rb b/app/models/proposal.rb
index 2d052cfad..99253e56f 100644
--- a/app/models/proposal.rb
+++ b/app/models/proposal.rb
@@ -14,6 +14,7 @@ class Proposal < ActiveRecord::Base
include ActsAsParanoidAliases
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
+ belongs_to :geozone
has_many :comments, as: :commentable
validates :title, presence: true
@@ -42,7 +43,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_relevance , -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
-
+
pg_search_scope :pg_search, {
against: {
title: 'A',
@@ -70,6 +71,7 @@ class Proposal < ActiveRecord::Base
}
tag_list.each{ |tag| values[tag] = 'D' }
values[author.username] = 'D'
+ values[geozone.name] = 'D' if geozone.present?
values
end
diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb
index adf7c432d..b26ac555b 100644
--- a/app/views/debates/_form.html.erb
+++ b/app/views/debates/_form.html.erb
@@ -15,14 +15,11 @@
<%= f.label :tag_list, t("debates.form.tags_label") %>
<%= t("debates.form.tags_instructions") %>
-
- <% @featured_tags.each do |tag| %>
- <%= tag.name %>
- <% end %>
-
- <%= f.text_field :tag_list, value: @debate.tag_list.to_s, label: false, placeholder: t("debates.form.tags_placeholder"), class: 'js-tag-list' %>
-
+ <%= f.text_field :tag_list, value: @debate.tag_list.to_s,
+ label: false,
+ placeholder: t("debates.form.tags_placeholder") %>
+
<% if @debate.new_record? %>
<%= f.label :terms_of_service do %>
@@ -44,6 +41,4 @@
<%= f.submit(class: "button radius", value: t("debates.#{action_name}.form.submit_button")) %>
-<% end %>
-
-
+<% end %>
\ No newline at end of file
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb
index f1c12e1b7..b1a316887 100644
--- a/app/views/debates/index.html.erb
+++ b/app/views/debates/index.html.erb
@@ -47,5 +47,6 @@
<%= render "shared/tag_cloud", taggable: 'debate' %>
+
diff --git a/app/views/debates/map.html.erb b/app/views/debates/map.html.erb
new file mode 100644
index 000000000..4c8e7807a
--- /dev/null
+++ b/app/views/debates/map.html.erb
@@ -0,0 +1 @@
+<%= render 'shared/map', new_url_path: new_debate_path %>
\ No newline at end of file
diff --git a/app/views/proposals/_categories.html.erb b/app/views/proposals/_categories.html.erb
new file mode 100644
index 000000000..4d429b055
--- /dev/null
+++ b/app/views/proposals/_categories.html.erb
@@ -0,0 +1,9 @@
+
+
+
+
+
+ <% @categories.each do |category| %>
+ <%= link_to category.name, proposals_path(search: category.name) %>
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb
index 97e1ecb6b..af1d219d3 100644
--- a/app/views/proposals/_form.html.erb
+++ b/app/views/proposals/_form.html.erb
@@ -39,15 +39,27 @@
<%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %>
+
+ <%= f.label :geozone_id, t("spending_proposals.form.geozone") %>
+ <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
+
+
<%= f.label :tag_list, t("proposals.form.tags_label") %>
<%= t("proposals.form.tags_instructions") %>
-
- <% @featured_tags.each do |tag| %>
+
+
+
+
+ <%= f.text_field :tag_list, value: @proposal.tag_list.to_s,
+ label: false,
+ placeholder: t("proposals.form.tags_placeholder"),
+ class: 'js-tag-list' %>
<% if current_user.unverified? %>
@@ -79,4 +91,4 @@
<%= f.submit(class: "button radius", value: t("proposals.#{action_name}.form.submit_button")) %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/proposals/_geozones.html.erb b/app/views/proposals/_geozones.html.erb
new file mode 100644
index 000000000..ccaa21e65
--- /dev/null
+++ b/app/views/proposals/_geozones.html.erb
@@ -0,0 +1,6 @@
+
+
+
+<%= link_to map_proposals_path, id: 'map' do %>
+ <%= image_tag("map.jpg") %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb
index 3469ecdb9..71cdb54a5 100644
--- a/app/views/proposals/index.html.erb
+++ b/app/views/proposals/index.html.erb
@@ -54,7 +54,10 @@
+
diff --git a/app/views/proposals/map.html.erb b/app/views/proposals/map.html.erb
new file mode 100644
index 000000000..84c7721f2
--- /dev/null
+++ b/app/views/proposals/map.html.erb
@@ -0,0 +1 @@
+<%= render 'shared/map', new_url_path: new_proposal_path %>
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb
index b4ed62531..d298327f9 100644
--- a/app/views/proposals/show.html.erb
+++ b/app/views/proposals/show.html.erb
@@ -64,6 +64,8 @@
<%= render 'shared/tags', taggable: @proposal %>
+ <%= render 'shared/geozone', geozonable: @proposal %>
+
<%= render 'proposals/actions', proposal: @proposal %>
diff --git a/app/views/shared/_geozone.html.erb b/app/views/shared/_geozone.html.erb
new file mode 100644
index 000000000..491cec031
--- /dev/null
+++ b/app/views/shared/_geozone.html.erb
@@ -0,0 +1,3 @@
+
+ <%= geozone_name(geozonable) %>
+
diff --git a/app/views/shared/_map.html.erb b/app/views/shared/_map.html.erb
new file mode 100644
index 000000000..f7d409dba
--- /dev/null
+++ b/app/views/shared/_map.html.erb
@@ -0,0 +1,52 @@
+
+
+
+
<%= t("map.title") %>
+
+
+
+
+ <% @geozones.each do |geozone| %>
+ - <%= link_to geozone.name, proposals_path(search: geozone.name) %>
+ <% end %>
+
+
+
+
+ <%= image_tag("map.jpg", usemap: "#map") %>
+
+
+
+
+
+
<%= t("map.proposal_for_district") %>
+
+ <%= form_for(@resource, url: new_url_path, method: :get ) do |f| %>
+
+ <%= f.label :geozone_id, t("map.select_district") %>
+ <%= f.select :geozone_id, geozone_select_options,
+ {include_blank: t("geozones.none"), label: false} %>
+
+
+
+ <%= f.submit(class: "button radius", value: t("map.start_proposal")) %>
+
+ <% end %>
+
+
+
+
+
+
diff --git a/app/views/shared/_tag_cloud.html.erb b/app/views/shared/_tag_cloud.html.erb
index fe46b6263..06bf85c2b 100644
--- a/app/views/shared/_tag_cloud.html.erb
+++ b/app/views/shared/_tag_cloud.html.erb
@@ -1,7 +1,8 @@
-
<%= t("shared.tags_cloud.tags") %>
+
+
<% tag_cloud @tag_cloud, %w[s m l] do |tag, css_class| %>
<%= link_to taggable_path(taggable, tag.name), class: css_class do %>
<%= tag.name %>
@@ -9,3 +10,4 @@
<% end %>
<% end %>
+
diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb
index 17f158d8a..8640a4d0c 100644
--- a/app/views/shared/_tags.html.erb
+++ b/app/views/shared/_tags.html.erb
@@ -1,7 +1,7 @@
<%- limit ||= nil %>
<% if taggable.tags.any? %>
-
+
<% taggable.tag_list_with_limit(limit).each do |tag| %>
<%= link_to sanitize(tag.name), send("#{taggable.class.to_s.downcase.pluralize}_path", tag: tag.name) %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c3f035fc8..7e0bd1b46 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -84,7 +84,7 @@ en:
form:
debate_text: Initial debate text
debate_title: Debate title
- tags_instructions: Tag this debate. You can choose from our suggestions or enter your own.
+ tags_instructions: Tag this debate.
tags_label: Topics
tags_placeholder: Enter the tags you would like to use, separated by commas (',')
index:
@@ -225,6 +225,11 @@ en:
one: Someone replied to your comment on
other: There are %{count} new replies to your comment on
title: Notifications
+ map:
+ title: "Districts"
+ proposal_for_district: "Start a proposal for your district"
+ select_district: Scope of operation
+ start_proposal: Create a proposal
omniauth:
facebook:
sign_in: Sign in with Facebook
@@ -259,7 +264,8 @@ en:
proposal_title: Proposal title
proposal_video_url: Link to external video
proposal_video_url_note: You may add a link to YouTube or Vimeo
- tags_instructions: Tag this proposal. You can choose from our tags or add your own.
+ tag_category_label: "Categories"
+ tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
tags_label: Tags
tags_placeholder: Enter the tags you would like to use, separated by commas (',')
index:
@@ -360,6 +366,8 @@ en:
print_button: Print this info
tags_cloud:
tags: Trending
+ districts: "Districts"
+ categories: "Categories"
unflag: Unflag
simple_captcha:
label: Enter the text from the image in the box below
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 87cabe85d..848a14bf9 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -84,7 +84,7 @@ es:
form:
debate_text: Texto inicial del debate
debate_title: Título del debate
- tags_instructions: Etiqueta este debate. Puedes elegir entre nuestras propuestas o introducir las que desees.
+ tags_instructions: Etiqueta este debate.
tags_label: Temas
tags_placeholder: "Escribe las etiquetas que desees separadas por coma (',')"
index:
@@ -225,6 +225,11 @@ es:
one: Hay una respuesta nueva a tu comentario en
other: Hay %{count} nuevas respuestas a tu comentario en
title: Notificaciones
+ map:
+ title: "Distritos"
+ proposal_for_district: "Crea una propuesta para tu distrito"
+ select_district: "Ámbito de actuación"
+ start_proposal: Crea una propuesta
omniauth:
facebook:
sign_in: Entra con Facebook
@@ -259,8 +264,9 @@ es:
proposal_title: Título de la propuesta
proposal_video_url: Enlace a vídeo externo
proposal_video_url_note: Puedes añadir un enlace a YouTube o Vimeo
- tags_instructions: Etiqueta esta propuesta. Puedes elegir entre nuestras sugerencias o introducir las que desees.
+ tags_instructions: "Etiqueta esta propuesta. Puedes elegir entre las categorías propuestas o introducir las que desees"
tags_label: Temas
+ tag_category_label: "Categorías"
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
index:
featured_proposals: Destacadas
@@ -360,6 +366,8 @@ es:
print_button: Imprimir esta información
tags_cloud:
tags: Tendencias
+ districts: "Distritos"
+ categories: "Categorías"
unflag: Deshacer denuncia
simple_captcha:
label: Introduce el texto de la imagen en la siguiente caja
diff --git a/config/routes.rb b/config/routes.rb
index 9c7146dcf..37578ed20 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -27,10 +27,6 @@ Rails.application.routes.draw do
patch :do_finish_signup, to: 'users/registrations#do_finish_signup'
end
- # The priority is based upon order of creation: first created -> highest priority.
- # See how all your routes lay out with "rake routes".
-
- # You can have the root of your site routed with "root"
root 'welcome#index'
get '/welcome', to: 'welcome#welcome'
get '/highlights', to: 'welcome#highlights', as: :highlights
@@ -42,6 +38,10 @@ Rails.application.routes.draw do
put :flag
put :unflag
end
+
+ collection do
+ get :map
+ end
end
resources :proposals do
@@ -51,6 +51,10 @@ Rails.application.routes.draw do
put :flag
put :unflag
end
+
+ collection do
+ get :map
+ end
end
resources :comments, only: [:create, :show], shallow: true do
@@ -229,55 +233,6 @@ Rails.application.routes.draw do
resources :spending_proposals, only: [:new, :create, :show]
end
- # Example of regular route:
- # get 'products/:id' => 'catalog#view'
-
- # Example of named route that can be invoked with purchase_url(id: product.id)
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
- # Example resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Example resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Example resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Example resource route with more complex sub-resources:
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', on: :collection
- # end
- # end
-
- # Example resource route with concerns:
- # concern :toggleable do
- # post 'toggle'
- # end
- # resources :posts, concerns: :toggleable
- # resources :photos, concerns: :toggleable
-
- # Example resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener"
end
@@ -285,7 +240,6 @@ Rails.application.routes.draw do
mount Tolk::Engine => '/translate', :as => 'tolk'
# static pages
-
get '/blog' => redirect("http://diario.madrid.es/participa/")
resources :pages, path: '/', only: [:show]
-end
+end
\ No newline at end of file
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index c20393d06..4f638758a 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -71,11 +71,27 @@ end
org_user_ids = User.organizations.pluck(:id)
not_org_users = User.where(['users.id NOT IN(?)', org_user_ids])
+puts "Creating Tags Categories"
+
+ActsAsTaggableOn::Tag.create!(name: "Asociaciones", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Cultura", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Deportes", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Derechos Sociales", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Economía", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Empleo", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Equidad", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true , kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category")
+ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category")
puts "Creating Debates"
tags = Faker::Lorem.words(25)
-
(1..30).each do |i|
author = User.reorder("RANDOM()").first
description = "#{Faker::Lorem.paragraphs.join('
')}
"
@@ -84,14 +100,30 @@ tags = Faker::Lorem.words(25)
created_at: rand((Time.now - 1.week) .. Time.now),
description: description,
tag_list: tags.sample(3).join(','),
+ geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
puts " #{debate.title}"
end
+
+tags = ActsAsTaggableOn::Tag.where(kind: 'category')
+(1..30).each do |i|
+ author = User.reorder("RANDOM()").first
+ description = "#{Faker::Lorem.paragraphs.join('
')}
"
+ debate = Debate.create!(author: author,
+ title: Faker::Lorem.sentence(3).truncate(60),
+ created_at: rand((Time.now - 1.week) .. Time.now),
+ description: description,
+ tag_list: tags.sample(3).join(','),
+ geozone: Geozone.reorder("RANDOM()").first,
+ terms_of_service: "1")
+ puts " #{debate.title}"
+end
+
+
puts "Creating Proposals"
tags = Faker::Lorem.words(25)
-
(1..30).each do |i|
author = User.reorder("RANDOM()").first
description = "#{Faker::Lorem.paragraphs.join('
')}
"
@@ -104,6 +136,26 @@ tags = Faker::Lorem.words(25)
description: description,
created_at: rand((Time.now - 1.week) .. Time.now),
tag_list: tags.sample(3).join(','),
+ geozone: Geozone.reorder("RANDOM()").first,
+ terms_of_service: "1")
+ puts " #{proposal.title}"
+end
+
+
+tags = ActsAsTaggableOn::Tag.where(kind: 'category')
+(1..30).each do |i|
+ author = User.reorder("RANDOM()").first
+ description = "#{Faker::Lorem.paragraphs.join('
')}
"
+ proposal = Proposal.create!(author: author,
+ title: Faker::Lorem.sentence(3).truncate(60),
+ question: Faker::Lorem.sentence(3),
+ summary: Faker::Lorem.sentence(3),
+ responsible_name: Faker::Name.name,
+ external_url: Faker::Internet.url,
+ description: description,
+ created_at: rand((Time.now - 1.week) .. Time.now),
+ tag_list: tags.sample(3).join(','),
+ geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
puts " #{proposal.title}"
end
@@ -232,4 +284,4 @@ puts "Confirming hiding in debates, comments & proposals"
Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide)
Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
-Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
+Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
\ No newline at end of file
diff --git a/db/migrate/20160119132601_add_kind_to_tags.rb b/db/migrate/20160119132601_add_kind_to_tags.rb
new file mode 100644
index 000000000..a4d196517
--- /dev/null
+++ b/db/migrate/20160119132601_add_kind_to_tags.rb
@@ -0,0 +1,5 @@
+class AddKindToTags < ActiveRecord::Migration
+ def change
+ add_column :tags, :kind, :string
+ end
+end
diff --git a/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb b/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb
new file mode 100644
index 000000000..ad2b0cdff
--- /dev/null
+++ b/db/migrate/20160122124847_add_geozone_to_proposals_and_debates.rb
@@ -0,0 +1,9 @@
+class AddGeozoneToProposalsAndDebates < ActiveRecord::Migration
+ def change
+ add_column :proposals, :geozone_id, :integer, default: nil
+ add_index :proposals, :geozone_id
+
+ add_column :debates, :geozone_id, :integer, default: nil
+ add_index :debates, :geozone_id
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2facd1874..df5bbc3a9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
t.integer "cached_votes_score", default: 0
t.integer "hot_score", limit: 8, default: 0
t.integer "confidence_score", default: 0
+ t.integer "geozone_id"
end
add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree
@@ -127,6 +128,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
+ add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
add_index "debates", ["title"], name: "index_debates_on_title", using: :btree
@@ -199,7 +201,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
create_table "locks", force: :cascade do |t|
t.integer "user_id"
t.integer "tries", default: 0
- t.datetime "locked_until", default: '2000-01-01 00:01:01', null: false
+ t.datetime "locked_until", default: '2000-01-01 07:01:01', null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@@ -252,12 +254,14 @@ ActiveRecord::Schema.define(version: 20160122153329) do
t.string "video_url"
t.integer "physical_votes", default: 0
t.tsvector "tsv"
+ t.integer "geozone_id"
end
add_index "proposals", ["author_id", "hidden_at"], name: "index_proposals_on_author_id_and_hidden_at", using: :btree
add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
+ add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree
add_index "proposals", ["question"], name: "index_proposals_on_question", using: :btree
@@ -315,6 +319,7 @@ ActiveRecord::Schema.define(version: 20160122153329) do
t.boolean "featured", default: false
t.integer "debates_count", default: 0
t.integer "proposals_count", default: 0
+ t.string "kind"
t.integer "spending_proposals_count", default: 0
end
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 95ff7ac89..69d764c69 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -106,27 +106,6 @@ feature 'Debates' do
expect(page).to have_content "Debate created successfully."
end
- scenario 'Failed creation goes back to new showing featured tags' do
- featured_tag = create(:tag, :featured)
- tag = create(:tag)
- login_as(create(:user))
-
- visit new_debate_path
- fill_in 'debate_title', with: ""
- fill_in 'debate_description', with: 'Very important issue...'
- fill_in 'debate_captcha', with: correct_captcha_text
- check 'debate_terms_of_service'
-
- click_button "Start a debate"
-
- expect(page).to_not have_content "Debate created successfully."
- expect(page).to have_content "error"
- within(".tags") do
- expect(page).to have_content featured_tag.name
- expect(page).to_not have_content tag.name
- end
- end
-
scenario 'Errors on create' do
author = create(:user)
login_as(author)
@@ -204,27 +183,43 @@ feature 'Debates' do
login_as(author)
end
- scenario 'using featured tags', :js do
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- create(:tag, :featured, name: tag_name)
- end
+ pending 'Category tags', :js do
+ education = create(:tag, name: 'Education', kind: 'category')
+ health = create(:tag, name: 'Health', kind: 'category')
visit new_debate_path
- fill_in 'debate_title', with: 'A test'
- fill_in_ckeditor 'debate_description', with: 'A test'
+ fill_in 'debate_title', with: 'Testing auto link'
+ fill_in 'debate_description', with: " click me http://example.org"
fill_in 'debate_captcha', with: correct_captcha_text
check 'debate_terms_of_service'
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- find('.js-add-tag-link', text: tag_name).click
- end
-
+ find('.js-add-tag-link', text: 'Education').click
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- expect(page).to have_content tag_name
+
+ within "#tags" do
+ expect(page).to have_content 'Education'
+ expect(page).to_not have_content 'Health'
+ end
+ end
+
+ scenario 'Custom tags' do
+ visit new_debate_path
+
+ fill_in 'debate_title', with: "Great title"
+ fill_in 'debate_description', with: 'Very important issue...'
+ fill_in 'debate_captcha', with: correct_captcha_text
+ check 'debate_terms_of_service'
+
+ fill_in 'debate_tag_list', with: 'Refugees, Solidarity'
+ click_button 'Start a debate'
+
+ expect(page).to have_content 'Debate created successfully.'
+ within "#tags" do
+ expect(page).to have_content 'Refugees'
+ expect(page).to have_content 'Solidarity'
end
end
@@ -323,27 +318,6 @@ feature 'Debates' do
expect(page).to have_content "Debate updated successfully."
end
- scenario 'Failed update goes back to edit showing featured tags' do
- debate = create(:debate)
- featured_tag = create(:tag, :featured)
- tag = create(:tag)
- login_as(debate.author)
-
- visit edit_debate_path(debate)
- expect(current_path).to eq(edit_debate_path(debate))
-
- fill_in 'debate_title', with: ""
- fill_in 'debate_captcha', with: correct_captcha_text
- click_button "Save changes"
-
- expect(page).to_not have_content "Debate updated successfully."
- expect(page).to have_content "error"
- within(".tags") do
- expect(page).to have_content featured_tag.name
- expect(page).to_not have_content tag.name
- end
- end
-
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per debate' do
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
@@ -890,4 +864,67 @@ feature 'Debates' do
visit debate_path(debate)
expect(page).to have_content('User deleted')
end
+
+ context "Filter" do
+
+ pending "By category" do
+ education = create(:tag, name: 'Education', kind: 'category')
+ health = create(:tag, name: 'Health', kind: 'category')
+
+ debate1 = create(:debate, tag_list: education.name)
+ debate2 = create(:debate, tag_list: health.name)
+
+ visit debates_path
+
+ within "#categories" do
+ click_link "Education"
+ end
+
+ within("#debates") do
+ expect(page).to have_css('.debate', count: 1)
+ expect(page).to have_content(debate1.title)
+ end
+ end
+
+ context "By geozone" do
+
+ background do
+ geozone1 = Geozone.create(name: "California")
+ geozone2 = Geozone.create(name: "New York")
+
+ @debate1 = create(:debate, geozone: geozone1)
+ @debate2 = create(:debate, geozone: geozone2)
+ end
+
+ pending "From map" do
+ visit debates_path
+
+ click_link "map"
+ within("#html_map") do
+ url = find("area[title='California']")[:href]
+ visit url
+ end
+
+ within("#debates") do
+ expect(page).to have_css('.debate', count: 1)
+ expect(page).to have_content(@debate1.title)
+ end
+ end
+
+ pending "From geozone list" do
+ visit debates_path
+
+ click_link "map"
+ within("#geozones") do
+ click_link "California"
+ end
+
+ within("#debates") do
+ expect(page).to have_css('.debate', count: 1)
+ expect(page).to have_content(@debate1.title)
+ end
+ end
+ end
+ end
+
end
diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb
index 0ef313704..0310e6311 100644
--- a/spec/features/proposals_spec.rb
+++ b/spec/features/proposals_spec.rb
@@ -166,31 +166,6 @@ feature 'Proposals' do
expect(page).to have_content "Proposal created successfully."
end
- scenario 'Failed creation goes back to new showing featured tags' do
- featured_tag = create(:tag, :featured)
- tag = create(:tag)
- login_as(create(:user))
-
- visit new_proposal_path
- fill_in 'proposal_title', with: ""
- fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
- fill_in 'proposal_summary', with: 'In summary, what we want is...'
- fill_in 'proposal_description', with: 'Very important issue...'
- fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
- fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
- fill_in 'proposal_captcha', with: correct_captcha_text
- check 'proposal_terms_of_service'
-
- click_button "Create proposal"
-
- expect(page).to_not have_content "Proposal created successfully."
- expect(page).to have_content "error"
- within(".tags") do
- expect(page).to have_content featured_tag.name
- expect(page).to_not have_content tag.name
- end
- end
-
scenario 'Errors on create' do
author = create(:user)
login_as(author)
@@ -271,42 +246,67 @@ feature 'Proposals' do
expect(page.html).to_not include ""
end
- context 'Tagging proposals' do
+ context 'Tagging' do
let(:author) { create(:user) }
background do
login_as(author)
end
- scenario 'using featured tags', :js do
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- create(:tag, :featured, name: tag_name)
- end
+ scenario 'Category tags', :js do
+ education = create(:tag, name: 'Education', kind: 'category')
+ health = create(:tag, name: 'Health', kind: 'category')
visit new_proposal_path
- fill_in 'proposal_title', with: 'A test with enough characters'
+ fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in_ckeditor 'proposal_description', with: 'A description with enough characters'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
+ fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- find('.js-add-tag-link', text: tag_name).click
- end
-
+ find('.js-add-tag-link', text: 'Education').click
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
- ['Medio Ambiente', 'Ciencia'].each do |tag_name|
- expect(page).to have_content tag_name
+
+ within "#tags" do
+ expect(page).to have_content 'Education'
+ expect(page).to_not have_content 'Health'
+ end
+ end
+
+ scenario 'Custom tags' do
+ visit new_proposal_path
+
+ fill_in 'proposal_title', with: 'Help refugees'
+ fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
+ fill_in 'proposal_summary', with: 'In summary, what we want is...'
+ fill_in 'proposal_description', with: 'This is very important because...'
+ fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
+ fill_in 'proposal_video_url', with: 'http://youtube.com'
+ fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
+ fill_in 'proposal_captcha', with: correct_captcha_text
+ check 'proposal_terms_of_service'
+
+ fill_in 'proposal_tag_list', with: 'Refugees, Solidarity'
+ click_button 'Create proposal'
+
+ expect(page).to have_content 'Proposal created successfully.'
+ within "#tags" do
+ expect(page).to have_content 'Refugees'
+ expect(page).to have_content 'Solidarity'
end
end
scenario 'using dangerous strings' do
+ author = create(:user)
+ login_as(author)
+
visit new_proposal_path
fill_in 'proposal_title', with: 'A test of dangerous strings'
@@ -330,6 +330,61 @@ feature 'Proposals' do
end
end
+ context "Geozones" do
+
+ scenario "Default whole city" do
+ author = create(:user)
+ login_as(author)
+
+ visit new_proposal_path
+
+ fill_in 'proposal_title', with: 'Help refugees'
+ fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
+ fill_in 'proposal_summary', with: 'In summary, what we want is...'
+ fill_in 'proposal_description', with: 'This is very important because...'
+ fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
+ fill_in 'proposal_video_url', with: 'http://youtube.com'
+ fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
+ fill_in 'proposal_captcha', with: correct_captcha_text
+ check 'proposal_terms_of_service'
+
+ click_button 'Create proposal'
+
+ expect(page).to have_content 'Proposal created successfully.'
+ within "#geozone" do
+ expect(page).to have_content 'All city'
+ end
+ end
+
+ scenario "Specific geozone" do
+ geozone = create(:geozone, name: 'California')
+ geozone = create(:geozone, name: 'New York')
+ author = create(:user)
+ login_as(author)
+
+ visit new_proposal_path
+
+ fill_in 'proposal_title', with: 'Help refugees'
+ fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
+ fill_in 'proposal_summary', with: 'In summary, what we want is...'
+ fill_in 'proposal_description', with: 'This is very important because...'
+ fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
+ fill_in 'proposal_video_url', with: 'http://youtube.com'
+ fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
+ fill_in 'proposal_captcha', with: correct_captcha_text
+ check 'proposal_terms_of_service'
+
+ select('California', from: 'proposal_geozone_id')
+ click_button 'Create proposal'
+
+ expect(page).to have_content 'Proposal created successfully.'
+ within "#geozone" do
+ expect(page).to have_content 'California'
+ end
+ end
+
+ end
+
scenario 'Update should not be posible if logged user is not the author' do
proposal = create(:proposal)
expect(proposal).to be_editable
@@ -410,27 +465,6 @@ feature 'Proposals' do
expect(page).to have_content "Proposal updated successfully."
end
- scenario 'Failed update goes back to edit showing featured tags' do
- proposal = create(:proposal)
- featured_tag = create(:tag, :featured)
- tag = create(:tag)
- login_as(proposal.author)
-
- visit edit_proposal_path(proposal)
- expect(current_path).to eq(edit_proposal_path(proposal))
-
- fill_in 'proposal_title', with: ""
- fill_in 'proposal_captcha', with: correct_captcha_text
- click_button "Save changes"
-
- expect(page).to_not have_content "Proposal updated successfully."
- expect(page).to have_content "error"
- within(".tags") do
- expect(page).to have_content featured_tag.name
- expect(page).to_not have_content tag.name
- end
- end
-
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per proposal' do
create_featured_proposals
@@ -988,4 +1022,67 @@ feature 'Proposals' do
visit proposals_path
expect(page).to have_content('User deleted')
end
+
+ context "Filter" do
+
+ scenario "By category" do
+ education = create(:tag, name: 'Education', kind: 'category')
+ health = create(:tag, name: 'Health', kind: 'category')
+
+ proposal1 = create(:proposal, tag_list: education.name)
+ proposal2 = create(:proposal, tag_list: health.name)
+
+ visit proposals_path
+
+ within "#categories" do
+ click_link "Education"
+ end
+
+ within("#proposals") do
+ expect(page).to have_css('.proposal', count: 1)
+ expect(page).to have_content(proposal1.title)
+ end
+ end
+
+ context "By geozone" do
+
+ background do
+ geozone1 = Geozone.create(name: "California")
+ geozone2 = Geozone.create(name: "New York")
+
+ @proposal1 = create(:proposal, geozone: geozone1)
+ @proposal2 = create(:proposal, geozone: geozone2)
+ end
+
+ scenario "From map" do
+ visit proposals_path
+
+ click_link "map"
+ within("#html_map") do
+ url = find("area[title='California']")[:href]
+ visit url
+ end
+
+ within("#proposals") do
+ expect(page).to have_css('.proposal', count: 1)
+ expect(page).to have_content(@proposal1.title)
+ end
+ end
+
+ scenario "From geozone list" do
+ visit proposals_path
+
+ click_link "map"
+ within("#geozones") do
+ click_link "California"
+ end
+
+ within("#proposals") do
+ expect(page).to have_css('.proposal', count: 1)
+ expect(page).to have_content(@proposal1.title)
+ end
+ end
+ end
+ end
+
end
diff --git a/spec/lib/acts_as_taggable_on_spec.rb b/spec/lib/acts_as_taggable_on_spec.rb
index 2362e8745..dbf76d52b 100644
--- a/spec/lib/acts_as_taggable_on_spec.rb
+++ b/spec/lib/acts_as_taggable_on_spec.rb
@@ -66,7 +66,4 @@ describe 'ActsAsTaggableOn' do
end
end
-
-
-
end
diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb
index 8eac2633c..5ce8c6d0e 100644
--- a/spec/models/debate_spec.rb
+++ b/spec/models/debate_spec.rb
@@ -455,6 +455,13 @@ describe Debate do
expect(results).to eq([debate])
end
+ xit "searches by geozone" do
+ geozone = create(:geozone, name: 'California')
+ debate = create(:debate, geozone: geozone)
+ results = Debate.search('California')
+ expect(results).to eq([debate])
+ end
+
end
context "stemming" do
diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb
index 0ee61744d..598c2136e 100644
--- a/spec/models/proposal_spec.rb
+++ b/spec/models/proposal_spec.rb
@@ -402,6 +402,13 @@ describe Proposal do
expect(results).to eq([proposal])
end
+ it "searches by geozone" do
+ geozone = create(:geozone, name: 'California')
+ proposal = create(:proposal, geozone: geozone)
+ results = Proposal.search('California')
+ expect(results).to eq([proposal])
+ end
+
end
context "stemming" do