Merge pull request #11 from AyuntamientoMadrid/devise_debates-11
Integrar devise con debates (ruby)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class DebatesController < ApplicationController
|
||||
before_action :set_debate, only: [:show, :edit, :update]
|
||||
|
||||
before_action :authenticate_user!, only: [:new, :create]
|
||||
|
||||
def index
|
||||
@debates = Debate.all
|
||||
end
|
||||
@@ -16,7 +17,9 @@ class DebatesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@debate = Debate.create(debate_params)
|
||||
@debate = Debate.new(debate_params)
|
||||
@debate.author = current_user
|
||||
@debate.save
|
||||
respond_with @debate
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class Debate < ActiveRecord::Base
|
||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,8 @@
|
||||
class User < ActiveRecord::Base
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<div class='debate'>
|
||||
<p><%= link_to debate.title, debate %></p>
|
||||
<p><%= debate.description %></p>
|
||||
<p>Creado el: <%= l debate.created_at.to_date %></p>
|
||||
<p>
|
||||
Creado el: <%= l debate.created_at.to_date %>
|
||||
por: <%= debate.author.name %>
|
||||
</p>
|
||||
</div>
|
||||
<br/><br/>
|
||||
@@ -20,7 +20,7 @@
|
||||
<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 %>
|
||||
|
||||
<% if action_name == 'new' %>
|
||||
<% if @debate.new_record? %>
|
||||
<%= f.check_box :terms_of_service %>
|
||||
Acepto la política de privacidad y el aviso legal
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<div id="debate-<%= @debate.id %>">
|
||||
<p><%= @debate.title %></p>
|
||||
<p><%= @debate.description %></p>
|
||||
<p>Creado el: <%= l @debate.created_at.to_date %></p>
|
||||
<p>
|
||||
Creado el: <%= l @debate.created_at.to_date %>
|
||||
por: <%= @debate.author.name %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= link_to 'Edit', edit_debate_path(@debate) %> |
|
||||
|
||||
@@ -11,6 +11,7 @@ FactoryGirl.define do
|
||||
title 'Debate title'
|
||||
description 'Debate description'
|
||||
terms_of_service '1'
|
||||
association :author, factory: :user
|
||||
end
|
||||
|
||||
end
|
||||
@@ -12,6 +12,7 @@ feature 'Debates' do
|
||||
expect(page).to have_content "Debate title"
|
||||
expect(page).to have_content "Debate description"
|
||||
expect(page).to have_content "Creado el: #{I18n.l Date.today}"
|
||||
expect(page).to have_content "por: #{Debate.first.author.name}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,9 +24,13 @@ feature 'Debates' do
|
||||
expect(page).to have_content "Debate title"
|
||||
expect(page).to have_content "Debate description"
|
||||
expect(page).to have_content "Creado el: #{I18n.l Date.today}"
|
||||
expect(page).to have_content "por: #{debate.author.name}"
|
||||
end
|
||||
|
||||
scenario 'Create' do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'Acabar con los desahucios'
|
||||
fill_in 'debate_description', with: 'Esto es un tema muy importante porque...'
|
||||
@@ -36,6 +41,8 @@ feature 'Debates' do
|
||||
expect(page).to have_content 'Debate creado correctamente'
|
||||
expect(page).to have_content 'Acabar con los desahucios'
|
||||
expect(page).to have_content 'Esto es un tema muy importante porque...'
|
||||
expect(page).to have_content "Creado el: #{I18n.l Date.today}"
|
||||
expect(page).to have_content "por: #{author.name}"
|
||||
end
|
||||
|
||||
scenario 'Update' do
|
||||
|
||||
@@ -10,6 +10,11 @@ describe Debate do
|
||||
expect(@debate).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without an author" do
|
||||
@debate.author = nil
|
||||
expect(@debate).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a title" do
|
||||
@debate.title = nil
|
||||
expect(@debate).to_not be_valid
|
||||
|
||||
Reference in New Issue
Block a user