Merge 119b7f4959
into 998ef40d19
This commit is contained in:
commit
9a0c8842b4
6 changed files with 130 additions and 0 deletions
|
@ -39,6 +39,7 @@ class Ability
|
|||
can [:read, :update, :destroy], :account
|
||||
can :update, :account_terms
|
||||
can :create, :account_pd_declaration
|
||||
can :read, :account_block
|
||||
can :read, :dashboard
|
||||
can [:create, :subscribe, :unsubscribe], DiaryEntry
|
||||
can :update, DiaryEntry, :user => user
|
||||
|
|
20
app/controllers/accounts/blocks_controller.rb
Normal file
20
app/controllers/accounts/blocks_controller.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Accounts
|
||||
class BlocksController < ApplicationController
|
||||
layout "site"
|
||||
|
||||
before_action :authorize_web
|
||||
before_action :set_locale
|
||||
|
||||
authorize_resource :class => :account_block
|
||||
|
||||
def index
|
||||
unseen_block = current_user.blocks.where(:deactivates_at => nil).order(:id).take
|
||||
if unseen_block
|
||||
redirect_to unseen_block
|
||||
else
|
||||
active_block = current_user.blocks.active.order(:id).take
|
||||
redirect_to active_block if active_block
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
app/views/accounts/blocks/index.html.erb
Normal file
11
app/views/accounts/blocks/index.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<% content_for :heading do %>
|
||||
<h1><%= t ".title" %></h1>
|
||||
<% end %>
|
||||
|
||||
<p><%= t ".no_active_blocks" %></p>
|
||||
|
||||
<% if current_user.blocks.exists? %>
|
||||
<div class="mb-3">
|
||||
<%= link_to t(".review_button"), user_received_blocks_path(current_user), :class => "btn btn-outline-primary" %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -279,6 +279,11 @@ en:
|
|||
success: "User information updated successfully."
|
||||
destroy:
|
||||
success: "Account Deleted."
|
||||
blocks:
|
||||
index:
|
||||
title: Blocks on Me
|
||||
no_active_blocks: There are no active blocks on your account.
|
||||
review_button: Review past blocks
|
||||
deletions:
|
||||
show:
|
||||
title: Delete My Account
|
||||
|
|
|
@ -305,6 +305,7 @@ OpenStreetMap::Application.routes.draw do
|
|||
|
||||
resource :account, :only => [:show, :update, :destroy] do
|
||||
scope :module => :accounts do
|
||||
resources :blocks, :only => :index
|
||||
resource :terms, :only => [:show, :update]
|
||||
resource :pd_declaration, :only => [:show, :create]
|
||||
resource :deletion, :only => :show
|
||||
|
|
92
test/controllers/accounts/blocks_controller_test.rb
Normal file
92
test/controllers/accounts/blocks_controller_test.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
require "test_helper"
|
||||
|
||||
module Accounts
|
||||
class BlocksControllerTest < ActionDispatch::IntegrationTest
|
||||
##
|
||||
# test all routes which lead to this controller
|
||||
def test_routes
|
||||
assert_routing(
|
||||
{ :path => "/account/blocks", :method => :get },
|
||||
{ :controller => "accounts/blocks", :action => "index" }
|
||||
)
|
||||
end
|
||||
|
||||
def test_index_not_logged_in
|
||||
get account_blocks_path
|
||||
assert_redirected_to login_path(:referer => account_blocks_path)
|
||||
end
|
||||
|
||||
def test_index_not_blocked
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_response :success
|
||||
assert_dom "#content > .content-body" do
|
||||
assert_dom "p", :text => /no active blocks/
|
||||
assert_dom "a", :text => "Review past blocks", :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_index_with_inactive_block
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
create(:user_block, :expired, :user => user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_response :success
|
||||
assert_dom "#content > .content-body" do
|
||||
assert_dom "p", :text => /no active blocks/
|
||||
assert_dom "a", :text => "Review past blocks" do
|
||||
assert_dom "> @href", user_received_blocks_path(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_index_with_unseen_block
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
unseen_block = create(:user_block, :needs_view, :user => user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(unseen_block)
|
||||
end
|
||||
|
||||
def test_index_with_two_unseen_blocks
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
unseen_block1 = create(:user_block, :needs_view, :user => user)
|
||||
unseen_block2 = create(:user_block, :needs_view, :user => user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(unseen_block1)
|
||||
follow_redirect!
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(unseen_block2)
|
||||
end
|
||||
|
||||
def test_index_with_seen_block
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
seen_block = create(:user_block, :user => user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(seen_block)
|
||||
end
|
||||
|
||||
def test_index_with_seen_and_unseen_blocks
|
||||
user = create(:user)
|
||||
session_for(user)
|
||||
seen_block = create(:user_block, :user => user)
|
||||
unseen_block = create(:user_block, :needs_view, :user => user)
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(unseen_block)
|
||||
follow_redirect!
|
||||
|
||||
get account_blocks_path
|
||||
assert_redirected_to user_block_path(seen_block)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue