1
0
Fork 0

Change MembershipAppsController#show

This commit is contained in:
Alex Kotov 2018-12-14 11:17:02 +05:00
parent 0f18566c88
commit 98ed8f1cc8
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
8 changed files with 18 additions and 15 deletions

View file

@ -2,9 +2,10 @@
class MembershipAppsController < ApplicationController
before_action :set_membership_app, only: :show
before_action :verify_joined, only: :show
before_action :verify_not_joined, only: :new
# GET /membership_apps/:id
# GET /membership_app
def show
authorize @membership_app
end
@ -31,7 +32,6 @@ class MembershipAppsController < ApplicationController
remember_if_guest_account @membership_app.account
redirect_to membership_app_url(
@membership_app,
guest_token: @membership_app.account.guest_token,
)
end
@ -39,7 +39,14 @@ class MembershipAppsController < ApplicationController
private
def set_membership_app
@membership_app = MembershipApp.find params[:id]
@membership_app = current_account&.own_membership_app
end
def verify_joined
return if current_account&.own_membership_app
skip_authorization
redirect_to join_url
end
def verify_not_joined

View file

@ -14,7 +14,7 @@
<% end %>
<% unless current_account&.own_membership_app.nil? %>
<a role="button" class="btn btn-success btn-lg" href="<%= membership_app_path current_account.own_membership_app %>">
<a role="button" class="btn btn-success btn-lg" href="<%= membership_app_path %>">
<%= translate '.tracking' %>
</a>
<% end %>

View file

@ -1,10 +1,8 @@
<p><%= translate '.lead_text' %></p>
<%= link_to membership_app_url(
@membership_app,
guest_token: @membership_app.account.guest_token,
),
membership_app_url(
@membership_app,
guest_token: @membership_app.account.guest_token,
) %>

View file

@ -12,7 +12,7 @@ Rails.application.routes.draw do
get :join, to: 'membership_apps#new'
post :join, to: 'membership_apps#create'
resources :membership_apps, only: :show
resource :membership_app, only: :show
###############
# User routes #

View file

@ -16,5 +16,5 @@ Feature: Membership application
| Членство в других общественных организациях | Не скажу |
| Комментарий | Примите, плиз |
And I click the form button "Отправить заявление"
Then I am at "/membership_apps/\d+"
Then I am at "/membership_app"
And I see text "Ваше заявление в обработке"

View file

@ -9,7 +9,7 @@ Then 'I see membership application creation form' do
end
Then 'I see the membership application tracking page' do
expect(page.current_path).to match %r{\A/membership_apps/\d+\z}
expect(page.current_path).to eq '/membership_app'
expect(page).to have_css 'h2', text: 'Ваше заявление в обработке'
end

View file

@ -97,7 +97,6 @@ RSpec.describe 'POST /join' do
membership_app = MembershipApp.last
expect(response).to redirect_to membership_app_url(
membership_app,
guest_token: membership_app.account.guest_token,
)
end
@ -142,7 +141,6 @@ RSpec.describe 'POST /join' do
membership_app = MembershipApp.last
expect(response).to redirect_to membership_app_url(
membership_app,
guest_token: membership_app.account.guest_token,
)
end

View file

@ -2,8 +2,8 @@
require 'rails_helper'
RSpec.describe 'GET /membership_apps/:id' do
let :membership_app do
RSpec.describe 'GET /membership_app' do
let! :membership_app do
create :membership_app, account: owner
end
@ -11,7 +11,7 @@ RSpec.describe 'GET /membership_apps/:id' do
before do
sign_in current_account&.user if current_account&.user
get "/membership_apps/#{membership_app.id}"
get '/membership_app'
end
context 'when owner is authenticated' do
@ -24,7 +24,7 @@ RSpec.describe 'GET /membership_apps/:id' do
for_account_types nil, :guest, :usual, :superuser do
specify do
expect(response).to have_http_status :unauthorized
expect(response).to redirect_to join_url
end
end
end