stores a proposal notification
This commit is contained in:
29
app/controllers/proposal_notifications_controller.rb
Normal file
29
app/controllers/proposal_notifications_controller.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class ProposalNotificationsController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
def new
|
||||
@notification = ProposalNotification.new
|
||||
@proposal = Proposal.find(params[:proposal_id])
|
||||
end
|
||||
|
||||
def create
|
||||
@notification = ProposalNotification.new(notification_params)
|
||||
@proposal = Proposal.find(notification_params[:proposal_id])
|
||||
if @notification.save
|
||||
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@notification = ProposalNotification.find(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notification_params
|
||||
params.require(:proposal_notification).permit(:title, :body, :proposal_id)
|
||||
end
|
||||
|
||||
end
|
||||
8
app/models/proposal_notification.rb
Normal file
8
app/models/proposal_notification.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class ProposalNotification < ActiveRecord::Base
|
||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
||||
belongs_to :proposal
|
||||
|
||||
validates :title, presence: true
|
||||
validates :body, presence: true
|
||||
validates :proposal, presence: true
|
||||
end
|
||||
13
app/views/proposal_notifications/new.html.erb
Normal file
13
app/views/proposal_notifications/new.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<%= form_for @notification do |f| %>
|
||||
<%= render "shared/errors", resource: @notification %>
|
||||
|
||||
<%= f.label :title, t("proposal_notifications.new.title_label") %>
|
||||
<%= f.text_field :title, label: false %>
|
||||
|
||||
<%= f.label :body, t("proposal_notifications.new.body_label") %>
|
||||
<%= f.text_area :body, label: false %>
|
||||
|
||||
<%= f.hidden_field :proposal_id, value: @proposal.id %>
|
||||
|
||||
<%= f.submit t("proposal_notifications.new.submit_button") %>
|
||||
<% end %>
|
||||
2
app/views/proposal_notifications/show.html.erb
Normal file
2
app/views/proposal_notifications/show.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<div><%= @notification.title %></div>
|
||||
<div><%= @notification.body %></div>
|
||||
@@ -146,6 +146,7 @@ en:
|
||||
not_saved: 'prevented this %{resource} from being saved:'
|
||||
policy: Privacy Policy
|
||||
proposal: Proposal
|
||||
proposal_notification: "Notification"
|
||||
spending_proposal: Spending proposal
|
||||
user: Account
|
||||
verification/sms: phone
|
||||
@@ -360,6 +361,11 @@ en:
|
||||
update:
|
||||
form:
|
||||
submit_button: Save changes
|
||||
proposal_notifications:
|
||||
new:
|
||||
title_label: "Title"
|
||||
body_label: "Message"
|
||||
submit_button: "Send"
|
||||
shared:
|
||||
advanced_search:
|
||||
author_type: 'By author category'
|
||||
|
||||
@@ -146,6 +146,7 @@ es:
|
||||
not_saved: 'impidieron guardar %{resource}:'
|
||||
policy: Política de privacidad
|
||||
proposal: la propuesta
|
||||
proposal_notification: "la notificación"
|
||||
spending_proposal: la propuesta de gasto
|
||||
user: la cuenta
|
||||
verification/sms: el teléfono
|
||||
@@ -360,6 +361,11 @@ es:
|
||||
update:
|
||||
form:
|
||||
submit_button: Guardar cambios
|
||||
proposal_notifications:
|
||||
new:
|
||||
title_label: "Título"
|
||||
body_label: "Mensaje"
|
||||
submit_button: "Enviar"
|
||||
shared:
|
||||
advanced_search:
|
||||
author_type: 'Por categoría de autor'
|
||||
|
||||
@@ -6,7 +6,9 @@ en:
|
||||
notice: "%{resource_name} created successfully."
|
||||
debate: "Debate created successfully."
|
||||
proposal: "Proposal created successfully."
|
||||
proposal_notification: "Your message has been sent correctly."
|
||||
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
||||
|
||||
save_changes:
|
||||
notice: Changes saved
|
||||
update:
|
||||
|
||||
@@ -6,6 +6,7 @@ es:
|
||||
notice: "%{resource_name} creado correctamente."
|
||||
debate: "Debate creado correctamente."
|
||||
proposal: "Propuesta creada correctamente."
|
||||
proposal_notification: "Tu message ha sido enviado correctamente."
|
||||
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
||||
save_changes:
|
||||
notice: Cambios guardados
|
||||
|
||||
@@ -93,6 +93,8 @@ Rails.application.routes.draw do
|
||||
put :mark_all_as_read, on: :collection
|
||||
end
|
||||
|
||||
resources :proposal_notifications, only: [:new, :create, :show]
|
||||
|
||||
resource :verification, controller: "verification", only: [:show]
|
||||
|
||||
scope module: :verification do
|
||||
|
||||
12
db/migrate/20160601103338_create_proposal_notifications.rb
Normal file
12
db/migrate/20160601103338_create_proposal_notifications.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateProposalNotifications < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :proposal_notifications do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
t.integer :author_id
|
||||
t.integer :proposal_id
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
11
db/schema.rb
11
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160518141543) do
|
||||
ActiveRecord::Schema.define(version: 20160601103338) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -260,6 +260,15 @@ ActiveRecord::Schema.define(version: 20160518141543) do
|
||||
|
||||
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
|
||||
|
||||
create_table "proposal_notifications", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
t.integer "author_id"
|
||||
t.integer "proposal_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "proposals", force: :cascade do |t|
|
||||
t.string "title", limit: 80
|
||||
t.text "description"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" }
|
||||
|
||||
factory :user do
|
||||
@@ -326,4 +325,10 @@ FactoryGirl.define do
|
||||
post_started_at Time.now - 7.days
|
||||
post_ended_at Time.now + 7.days
|
||||
end
|
||||
|
||||
factory :proposal_notification do
|
||||
title "Thank you for supporting my proposal"
|
||||
body "Please let others know so we can make it happen"
|
||||
proposal
|
||||
end
|
||||
end
|
||||
|
||||
31
spec/features/proposal_notifications_spec.rb
Normal file
31
spec/features/proposal_notifications_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Proposal Notifications' do
|
||||
|
||||
scenario "Send a notification" do
|
||||
noelia = create(:user)
|
||||
vega = create(:user)
|
||||
|
||||
proposal = create(:proposal)
|
||||
#use correct path from my activity
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
expect(page).to have_content "Thank you for supporting my proposal"
|
||||
expect(page).to have_content "Please share it with others so we can make it happen!"
|
||||
end
|
||||
|
||||
scenario "Error messages" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
click_button "Send"
|
||||
|
||||
expect(page).to have_content error_message
|
||||
end
|
||||
|
||||
end
|
||||
25
spec/models/proposal_notification_spec.rb
Normal file
25
spec/models/proposal_notification_spec.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ProposalNotification do
|
||||
let(:notification) { build(:proposal_notification) }
|
||||
|
||||
it "should be valid" do
|
||||
expect(notification).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a title" do
|
||||
notification.title = nil
|
||||
expect(notification).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a body" do
|
||||
notification.body = nil
|
||||
expect(notification).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without an associated proposal" do
|
||||
notification.proposal = nil
|
||||
expect(notification).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user