ForumValidation controller and views
parent
cdcfc0310e
commit
39553ef97f
|
@ -18,8 +18,7 @@ guard :rspec, cmd: 'spring rspec' do
|
|||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
||||
# Rails example
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
||||
watch(%r{^app/([^\.]+).*?(\.haml|\.rb)$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
||||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
||||
watch('config/routes.rb') { "spec/routing" }
|
||||
|
|
|
@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
|
|||
rescue_from CanCan::AccessDenied, with: :authentication_error
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
||||
rescue_from ActionController::ParameterMissing, with: :wrong_parameters_error
|
||||
rescue_from ActiveRecord::RecordInvalid, with: :wrong_parameters_error
|
||||
|
||||
before_action :configure_devise_permitted_parameters, if: :devise_controller?
|
||||
|
||||
|
|
|
@ -1,2 +1,33 @@
|
|||
class ForumValidationsController < ApplicationController
|
||||
def create
|
||||
@forum_validation = ForumValidation.new resource_params
|
||||
@forum_validation.save! # server error if it fails, shouldn't happen
|
||||
redirect_to @forum_validation
|
||||
end
|
||||
|
||||
def update
|
||||
@forum_validation = ForumValidation.find params[:id]
|
||||
if @forum_validation.vid == params[:vid]
|
||||
if @forum_validation.validated?
|
||||
flash[:notice] = I18n.t('forum_validations.flash.update.already_success')
|
||||
else
|
||||
@forum_validation.associate_user_and_author!
|
||||
@forum_validation.user.give_ownership_of_authored!
|
||||
flash[:notice] = I18n.t('forum_validations.flash.update.success')
|
||||
end
|
||||
redirect_to @forum_validation
|
||||
else
|
||||
wrong_parameters_error
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resource_params
|
||||
params.require(:forum_validation).permit(:author_id, :user_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
%h1 Forum account validation
|
||||
|
||||
- if @forum_validation.validated?
|
||||
= t '.validated'
|
||||
- else
|
||||
= raw t '.not_validated'
|
||||
|
||||
%h2 Mods associated:
|
||||
|
||||
- @forum_validation.author.mods.each do |mod|
|
||||
= link_to mod.name, mod
|
||||
= link_to '[Edit]', [:edit, mod]
|
|
@ -0,0 +1,17 @@
|
|||
en:
|
||||
forum_validations:
|
||||
flash:
|
||||
update:
|
||||
success: "You account have been successfully linked to your forum account! You can now manage all the mods!"
|
||||
already_success: "You account has already been validated"
|
||||
|
||||
show:
|
||||
validated: |
|
||||
Your forum account has been validated!
|
||||
These are the mods that were associated with that account, you can now
|
||||
manage them yourself:
|
||||
not_validated: |
|
||||
Your forum account hasn't been validated yet, please
|
||||
<a href="http://www.factorioforums.com/forum/ucp.php?i=pm&folder=inbox">check your PMs inbox</a>
|
||||
and click the link we sent you.
|
||||
After you validate the forum account, you'll be able to manage all these mods associated with it:
|
|
@ -1,6 +1,4 @@
|
|||
Rails.application.routes.draw do
|
||||
resources :forum_validations, except: [:new, :edit]
|
||||
|
||||
namespace :api, path: '/', constraints: { subdomain: 'api' } do
|
||||
resources :mods, only: [:index, :show]
|
||||
resources :categories, only: [:index, :show] do
|
||||
|
@ -87,6 +85,12 @@ Rails.application.routes.draw do
|
|||
resources :mods, path: '/', only: :index
|
||||
end
|
||||
|
||||
resources :forum_validations, path: 'forum-validations', only: [:show, :create] do
|
||||
member do
|
||||
get '/validate', to: 'forum_validations#update'
|
||||
end
|
||||
end
|
||||
|
||||
get '/how-to-submit' => 'static#how_to_submit', as: :how_to_submit_static
|
||||
get '/how-to-install' => 'static#how_to_install', as: :how_to_install_static
|
||||
get '/how-to-make' => 'static#how_to_make', as: :how_to_make_static
|
||||
|
|
|
@ -1,5 +1,120 @@
|
|||
require 'rails_helper'
|
||||
describe ForumValidationsController, type: :controller do
|
||||
describe 'POST create' do
|
||||
it 'should create a new ForumValidation with the corresponding author and user' do
|
||||
user = create :user
|
||||
author = create :author
|
||||
post :create, forum_validation: { user_id: user.id, author_id: author.id }
|
||||
fv = ForumValidation.first
|
||||
expect(fv.user).to eq user
|
||||
expect(fv.author).to eq author
|
||||
expect(fv.validated).to eq false
|
||||
expect(fv.vid.size).to eq 50
|
||||
expect(response).to redirect_to fv
|
||||
end
|
||||
|
||||
RSpec.describe ForumValidationsController, type: :controller do
|
||||
it 'should throw a server error with invalid parameters' do
|
||||
post :create, forum_validation: { user_id: 1234, author_id: 4321 }
|
||||
expect(response).to have_http_status :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
# Yes, GET
|
||||
describe 'GET update' do
|
||||
before(:each) do
|
||||
@user = create :user
|
||||
@author = create :author
|
||||
create :mod, authors: [@author], owner: nil
|
||||
create :mod, authors: [@author], owner: nil
|
||||
@fv = create :forum_validation, user: @user, author: @author
|
||||
end
|
||||
|
||||
context 'with the correct #vid' do
|
||||
before(:each) do
|
||||
get :update, id: @fv.id, vid: @fv.vid
|
||||
@fv.reload
|
||||
@user.reload
|
||||
@author.reload
|
||||
end
|
||||
|
||||
it 'should set the fv to validated' do
|
||||
expect(@fv.validated).to eq true
|
||||
end
|
||||
|
||||
it 'should associate the user and author' do
|
||||
expect(@user.author).to eq @author
|
||||
expect(@author.user).to eq @user
|
||||
end
|
||||
|
||||
it 'should redirect to the fv' do
|
||||
expect(response).to redirect_to @fv
|
||||
end
|
||||
|
||||
it 'should set the corresponding flash message' do
|
||||
expect(flash[:notice]).to eq I18n.t('forum_validations.flash.update.success')
|
||||
end
|
||||
|
||||
it 'should set the ownership of all the mods associated with the author to the user' do
|
||||
expect(@author.mods[0].owner).to eq @user
|
||||
expect(@author.mods[1].owner).to eq @user
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with the incorrect #vid' do
|
||||
before(:each) do
|
||||
get :update, id: @fv.id, vid: 'rsniahsraeitn'
|
||||
@fv.reload
|
||||
@user.reload
|
||||
@author.reload
|
||||
end
|
||||
|
||||
it 'should still be #validated false' do
|
||||
expect(@fv.validated).to eq false
|
||||
end
|
||||
|
||||
it 'should NOT associate the user and author' do
|
||||
expect(@user.author).to eq nil
|
||||
expect(@author.user).to eq nil
|
||||
end
|
||||
|
||||
it 'throw a server error' do
|
||||
expect(response).to have_http_status :bad_request
|
||||
end
|
||||
|
||||
it 'should not set ownership of the mods associated with the author to the user' do
|
||||
expect(@author.mods[0].owner).to eq nil
|
||||
expect(@author.mods[1].owner).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an already validated ForumValidation' do
|
||||
before(:each) do
|
||||
@fv.associate_user_and_author!
|
||||
@fv.user.give_ownership_of_authored!
|
||||
get :update, id: @fv.id, vid: @fv.vid
|
||||
@fv.reload
|
||||
@user.reload
|
||||
@author.reload
|
||||
end
|
||||
|
||||
it 'should redirect the user to the fv' do
|
||||
expect(response).to redirect_to @fv
|
||||
end
|
||||
|
||||
it 'should set a different flash message' do
|
||||
expect(flash[:notice]).to eq I18n.t('forum_validations.flash.update.already_success')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET show' do
|
||||
it 'should render the show template' do
|
||||
@fv = create :forum_validation
|
||||
@m1 = create :mod, authors: [@fv.author]
|
||||
@m2 = create :mod, authors: [@fv.author]
|
||||
@fv.associate_user_and_author!
|
||||
@fv.user.give_ownership_of_authored!
|
||||
get :show, id: @fv.id
|
||||
expect(response).to render_template :show
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,4 +43,16 @@ describe ForumValidation, type: :model do
|
|||
expect(fv.validated).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
# describe '#send_pm' do
|
||||
# def send_pm
|
||||
# VCR.use_cassette('forum_validation', record: :new_episodes) do
|
||||
# subject.send_pm
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# it 'should authenticate and send a PM in the forum' do
|
||||
#
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
describe 'forum_validations/show', type: :view do
|
||||
before :each do
|
||||
@fv = create :forum_validation
|
||||
create :mod, authors: [@fv.author], name: 'Potato'
|
||||
create :mod, authors: [@fv.author], name: 'Salad'
|
||||
create :mod, authors: [@fv.author], name: 'Simulator'
|
||||
end
|
||||
|
||||
it 'display the list of mods associated with the author' do
|
||||
assign(:forum_validation, @fv)
|
||||
render
|
||||
expect(rendered).to match(/Potato.*Salad.*Simulator/m)
|
||||
end
|
||||
|
||||
context '#validated = false' do
|
||||
it 'should display a message indicating that the user is not validated' do
|
||||
@fv.validated = false
|
||||
assign(:forum_validation, @fv)
|
||||
render
|
||||
expect(rendered).to include I18n.t('forum_validations.show.not_validated')
|
||||
end
|
||||
end
|
||||
|
||||
context '#validated = true' do
|
||||
it 'should display a message indicating that the user is validated' do
|
||||
@fv.validated = true
|
||||
assign(:forum_validation, @fv)
|
||||
render
|
||||
expect(rendered).to include I18n.t('forum_validations.show.validated')
|
||||
end
|
||||
|
||||
it 'should display links to edit each the mods' do
|
||||
@fv.validated = true
|
||||
assign(:forum_validation, @fv)
|
||||
render
|
||||
expect(rendered).to have_link('', href: edit_mod_path(id: 'potato'))
|
||||
expect(rendered).to have_link('', href: edit_mod_path(id: 'salad'))
|
||||
expect(rendered).to have_link('', href: edit_mod_path(id: 'simulator'))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue