fixing conflicts [#7]
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -31,7 +31,7 @@ gem 'acts_as_commentable_with_threading'
|
||||
|
||||
# Use Capistrano for deployment
|
||||
# gem 'capistrano-rails', group: :development
|
||||
|
||||
gem 'acts-as-taggable-on'
|
||||
gem "responders"
|
||||
gem 'foundation-rails'
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ GEM
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
acts-as-taggable-on (3.5.0)
|
||||
activerecord (>= 3.2, < 5)
|
||||
acts_as_commentable_with_threading (2.0.0)
|
||||
activerecord (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
@@ -194,6 +196,7 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
acts-as-taggable-on
|
||||
acts_as_commentable_with_threading
|
||||
byebug
|
||||
capybara
|
||||
|
||||
7
app/assets/stylesheets/debates.scss
Normal file
7
app/assets/stylesheets/debates.scss
Normal file
@@ -0,0 +1,7 @@
|
||||
#tag_cloud {
|
||||
width: 400px;
|
||||
line-height: 1.6em;
|
||||
.s { font-size: 0.8em; }
|
||||
.m { font-size: 1.2em; }
|
||||
.l { font-size: 1.8em; }
|
||||
}
|
||||
@@ -3,8 +3,12 @@ class DebatesController < ApplicationController
|
||||
before_action :authenticate_user!, only: [:new, :create]
|
||||
|
||||
def index
|
||||
if params[:tag]
|
||||
@debates = Debate.tagged_with(params[:tag])
|
||||
else
|
||||
@debates = Debate.all
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
@@ -35,7 +39,7 @@ class DebatesController < ApplicationController
|
||||
end
|
||||
|
||||
def debate_params
|
||||
params.require(:debate).permit(:title, :description, :external_link, :terms_of_service)
|
||||
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
module ApplicationHelper
|
||||
|
||||
def tags(debate)
|
||||
debate.tag_list.map { |tag| link_to sanitize(tag), debates_path(tag: tag) }.join(', ').html_safe
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Debate < ActiveRecord::Base
|
||||
acts_as_commentable
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<div class='debate'>
|
||||
<div id="debate-<%= debate.id %>" class='debate'>
|
||||
<p><%= link_to debate.title, debate %></p>
|
||||
<p><%= debate.description %></p>
|
||||
|
||||
<p>
|
||||
Creado el: <%= l debate.created_at.to_date %>
|
||||
por: <%= debate.author.name %>
|
||||
</p>
|
||||
|
||||
<p><%= render 'shared/tags', debate: debate %></p>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<br/><br/><br/><br/>
|
||||
@@ -20,6 +20,11 @@
|
||||
<p>Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguiríamos con ella</p>
|
||||
<%= f.text_area :description %>
|
||||
|
||||
<div>
|
||||
<%= f.label :tag_list, "Temas (separados por comas)" %><br />
|
||||
<%= f.text_field :tag_list, value: @debate.tag_list.to_s %>
|
||||
</div>
|
||||
|
||||
<% if @debate.new_record? %>
|
||||
<%= f.check_box :terms_of_service %>
|
||||
Acepto la política de privacidad y el aviso legal
|
||||
|
||||
@@ -4,5 +4,7 @@
|
||||
<%= render @debates %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<%= render 'shared/tag_cloud' %>
|
||||
|
||||
<br/><br/>
|
||||
<%= link_to 'New Debate', new_debate_path %>
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= render 'shared/tags', debate: @debate %>
|
||||
|
||||
<br/><br/>
|
||||
Deja tu comentario
|
||||
<%= render 'comments/form', parent: @debate %>
|
||||
|
||||
|
||||
5
app/views/shared/_tag_cloud.html.erb
Normal file
5
app/views/shared/_tag_cloud.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<div id="tag-cloud">
|
||||
<% tag_cloud Debate.tag_counts, %w[s m l] do |tag, css_class| %>
|
||||
<%= link_to sanitize("#{tag.name}(#{tag.taggings_count})"), debates_path(tag: tag.name), class: css_class %>
|
||||
<% end %>
|
||||
</div>
|
||||
3
app/views/shared/_tags.html.erb
Normal file
3
app/views/shared/_tags.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% if debate.tags.any? %>
|
||||
Temas: <%= tags(debate) %>
|
||||
<% end %>
|
||||
1
config/initializers/acts_as_taggable_on.rb
Normal file
1
config/initializers/acts_as_taggable_on.rb
Normal file
@@ -0,0 +1 @@
|
||||
ActsAsTaggableOn.delimiter = ','
|
||||
@@ -0,0 +1,25 @@
|
||||
# This migration comes from acts_as_taggable_on_engine (originally 1)
|
||||
class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :tags do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :taggings do |t|
|
||||
t.references :tag
|
||||
t.references :taggable, polymorphic: true
|
||||
t.references :tagger, polymorphic: true
|
||||
t.string :context, limit: 128
|
||||
t.datetime :created_at
|
||||
end
|
||||
|
||||
add_index :tags, :name, unique: true
|
||||
add_index :taggings, :tag_id
|
||||
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :taggings
|
||||
drop_table :tags
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
# This migration comes from acts_as_taggable_on_engine (originally 3)
|
||||
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :tags, :taggings_count, :integer, default: 0
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :tags, :taggings_count
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -38,6 +38,26 @@ ActiveRecord::Schema.define(version: 20150718091702) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "taggings", force: :cascade do |t|
|
||||
t.integer "tag_id"
|
||||
t.integer "taggable_id"
|
||||
t.string "taggable_type"
|
||||
t.integer "tagger_id"
|
||||
t.string "tagger_type"
|
||||
t.string "context", limit: 128
|
||||
t.datetime "created_at"
|
||||
end
|
||||
|
||||
add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id"
|
||||
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"
|
||||
t.integer "taggings_count", default: 0
|
||||
end
|
||||
|
||||
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
||||
99
spec/features/tags_spec.rb
Normal file
99
spec/features/tags_spec.rb
Normal file
@@ -0,0 +1,99 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Tags' do
|
||||
|
||||
scenario 'Index' do
|
||||
earth = create(:debate, tag_list: 'Medio Ambiente')
|
||||
money = create(:debate, tag_list: 'Economía')
|
||||
|
||||
visit debates_path
|
||||
|
||||
within "#debate-#{earth.id}" do
|
||||
expect(page).to have_content "Temas: Medio Ambiente"
|
||||
end
|
||||
|
||||
within "#debate-#{money.id}" do
|
||||
expect(page).to have_content "Temas: Economía"
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Filtered' do
|
||||
2.times { create(:debate, tag_list: 'Salud') }
|
||||
2.times { create(:debate, tag_list: 'Hacienda') }
|
||||
|
||||
visit debates_path
|
||||
first(:link, "Salud").click
|
||||
|
||||
expect(page).to have_css('.debate', count: 2)
|
||||
expect(page).to have_content('Temas: Salud')
|
||||
expect(page).to_not have_content('Temas: Hacienda')
|
||||
end
|
||||
|
||||
scenario 'Show' do
|
||||
debate = create(:debate, tag_list: 'Hacienda, Economía')
|
||||
|
||||
visit debate_path(debate)
|
||||
|
||||
expect(page).to have_content "Temas: Hacienda, Economía"
|
||||
end
|
||||
|
||||
scenario 'Tag Cloud' do
|
||||
1.times { create(:debate, tag_list: 'Medio Ambiente') }
|
||||
5.times { create(:debate, tag_list: 'Corrupción') }
|
||||
10.times { create(:debate, tag_list: 'Economía') }
|
||||
|
||||
visit debates_path
|
||||
|
||||
within "#tag-cloud" do
|
||||
expect(page).to have_css(".s", text: "Medio Ambiente(1)")
|
||||
expect(page).to have_css(".m", text: "Corrupción(5)")
|
||||
expect(page).to have_css(".l", text: "Economía(10)")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'Title'
|
||||
fill_in 'debate_description', with: 'Description'
|
||||
check 'debate_terms_of_service'
|
||||
|
||||
fill_in 'debate_tag_list', with: "Impuestos, Economía, Hacienda"
|
||||
|
||||
click_button 'Crear Debate'
|
||||
|
||||
expect(page).to have_content 'Debate creado correctamente'
|
||||
expect(page).to have_content 'Temas: Impuestos, Economía, Hacienda'
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
debate = create(:debate, tag_list: 'Economía')
|
||||
|
||||
login_as(debate.author)
|
||||
visit edit_debate_path(debate)
|
||||
|
||||
expect(page).to have_selector("input[value='Economía']")
|
||||
|
||||
fill_in 'debate_tag_list', with: "Economía, Hacienda"
|
||||
click_button 'Actualizar Debate'
|
||||
|
||||
expect(page).to have_content 'Debate actualizado correctamente'
|
||||
expect(page).to have_content 'Temas: Economía, Hacienda'
|
||||
end
|
||||
|
||||
scenario 'Delete' do
|
||||
debate = create(:debate, tag_list: 'Economía')
|
||||
|
||||
login_as(debate.author)
|
||||
visit edit_debate_path(debate)
|
||||
|
||||
fill_in 'debate_tag_list', with: ""
|
||||
click_button 'Actualizar Debate'
|
||||
|
||||
expect(page).to have_content 'Debate actualizado correctamente'
|
||||
expect(page).to_not have_content 'Temas:'
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user