Merge branch 'stable' into develop
This commit is contained in:
commit
6fce81fc99
6 changed files with 55 additions and 62 deletions
|
|
@ -100,6 +100,9 @@ Contributions are very welcome, the hard work is done!
|
|||
|
||||
# 0.5.7.0
|
||||
|
||||
## Refactor
|
||||
* Internationalize controller rescue\_from text [#6554](https://github.com/diaspora/diaspora/pull/6554)
|
||||
|
||||
# Bug fixes
|
||||
Fix plural rules handling more than wanted as "one" [#6630](https://github.com/diaspora/diaspora/pull/6630)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ class AspectMembershipsController < ApplicationController
|
|||
respond_to :html, :json
|
||||
|
||||
def destroy
|
||||
aspect = current_user.aspects.joins(:aspect_memberships).where(:aspect_memberships=>{:id=>params[:id]}).first
|
||||
contact = current_user.contacts.joins(:aspect_memberships).where(:aspect_memberships=>{:id=>params[:id]}).first
|
||||
aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
|
||||
contact = current_user.contacts.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
|
||||
|
||||
raise ActiveRecord::RecordNotFound unless aspect.present? && contact.present?
|
||||
|
||||
raise Diaspora::NotMine unless current_user.mine?(aspect) &&
|
||||
current_user.mine?(contact)
|
||||
|
||||
membership = contact.aspect_memberships.where(:aspect_id => aspect.id).first
|
||||
membership = contact.aspect_memberships.where(aspect_id: aspect.id).first
|
||||
|
||||
raise ActiveRecord::RecordNotFound unless membership.present?
|
||||
|
||||
|
|
@ -26,17 +26,17 @@ class AspectMembershipsController < ApplicationController
|
|||
|
||||
# set the flash message
|
||||
if success
|
||||
flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success'
|
||||
flash.now[:notice] = I18n.t "aspect_memberships.destroy.success"
|
||||
else
|
||||
flash.now[:error] = I18n.t 'aspect_memberships.destroy.failure'
|
||||
flash.now[:error] = I18n.t "aspect_memberships.destroy.failure"
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if success
|
||||
render :json => AspectMembershipPresenter.new(membership).base_hash
|
||||
render json: AspectMembershipPresenter.new(membership).base_hash
|
||||
else
|
||||
render :text => membership.errors.full_messages, :status => 403
|
||||
render text: membership.errors.full_messages, status: 403
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -46,37 +46,36 @@ class AspectMembershipsController < ApplicationController
|
|||
|
||||
def create
|
||||
@person = Person.find(params[:person_id])
|
||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
||||
@aspect = current_user.aspects.where(id: params[:aspect_id]).first
|
||||
|
||||
@contact = current_user.share_with(@person, @aspect)
|
||||
|
||||
if @contact.present?
|
||||
flash.now[:notice] = I18n.t('aspects.add_to_aspect.success')
|
||||
flash.now[:notice] = I18n.t("aspects.add_to_aspect.success")
|
||||
respond_with do |format|
|
||||
format.json do
|
||||
render :json => AspectMembershipPresenter.new(
|
||||
AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first)
|
||||
render json: AspectMembershipPresenter.new(
|
||||
AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first)
|
||||
.base_hash
|
||||
end
|
||||
|
||||
format.all { redirect_to :back }
|
||||
end
|
||||
else
|
||||
flash.now[:error] = I18n.t('contacts.create.failure')
|
||||
render :nothing => true, :status => 409
|
||||
flash.now[:error] = I18n.t("contacts.create.failure")
|
||||
render nothing: true, status: 409
|
||||
end
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::StatementInvalid do
|
||||
render :text => "Duplicate record rejected.", :status => 400
|
||||
render text: I18n.t("aspect_memberships.destroy.invalid_statement"), status: 400
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::RecordNotFound do
|
||||
render :text => I18n.t('aspect_memberships.destroy.no_membership'), :status => 404
|
||||
render text: I18n.t("aspect_memberships.destroy.no_membership"), status: 404
|
||||
end
|
||||
|
||||
rescue_from Diaspora::NotMine do
|
||||
render :text => "You are not allowed to do that.", :status => 403
|
||||
render text: I18n.t("aspect_memberships.destroy.forbidden"), status: 403
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class InvitationCodesController < ApplicationController
|
|||
before_action :ensure_valid_invite_code
|
||||
|
||||
rescue_from ActiveRecord::RecordNotFound do
|
||||
redirect_to root_url, :notice => "That invite code is no longer valid"
|
||||
redirect_to root_url, :notice => I18n.t('invitation_codes.not_valid')
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class PostsController < ApplicationController
|
|||
end
|
||||
|
||||
rescue_from Diaspora::NotMine do
|
||||
render text: "You are not allowed to do that", status: 403
|
||||
render text: I18n.t("posts.show.forbidden"), status: 403
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -285,6 +285,8 @@ en:
|
|||
success: "Successfully removed person from aspect."
|
||||
failure: "Failed to remove person from aspect."
|
||||
no_membership: "Could not find the selected person in that aspect."
|
||||
forbidden: "You are not allowed to do that."
|
||||
invalid_statement: "Duplicate record rejected."
|
||||
|
||||
bookmarklet:
|
||||
heading: "Bookmarklet"
|
||||
|
|
@ -594,6 +596,8 @@ en:
|
|||
|
||||
invitation_codes:
|
||||
excited: "%{name} is excited to see you here."
|
||||
not_valid: "That invite code is no longer valid"
|
||||
|
||||
invitations:
|
||||
create:
|
||||
sent: "Invitations have been sent to: %{emails}"
|
||||
|
|
@ -1028,6 +1032,7 @@ en:
|
|||
destroy: "Delete"
|
||||
permalink: "Permalink"
|
||||
not_found: "Sorry, we couldn’t find that post."
|
||||
forbidden: "You are not allowed to do that"
|
||||
photos_by:
|
||||
zero: "No photos by %{author}"
|
||||
one: "One photo by %{author}"
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe AspectMembershipsController, :type => :controller do
|
||||
describe AspectMembershipsController, type: :controller do
|
||||
before do
|
||||
@aspect0 = alice.aspects.first
|
||||
@aspect1 = alice.aspects.create(:name => "another aspect")
|
||||
@aspect1 = alice.aspects.create(name: "another aspect")
|
||||
@aspect2 = bob.aspects.first
|
||||
|
||||
@contact = alice.contact_for(bob.person)
|
||||
|
|
@ -15,68 +15,54 @@ describe AspectMembershipsController, :type => :controller do
|
|||
alice.save
|
||||
sign_in :user, alice
|
||||
allow(@controller).to receive(:current_user).and_return(alice)
|
||||
request.env["HTTP_REFERER"] = 'http://' + request.host
|
||||
request.env["HTTP_REFERER"] = "http://" + request.host
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
describe "#create" do
|
||||
before do
|
||||
@person = eve.person
|
||||
end
|
||||
|
||||
it 'succeeds' do
|
||||
post :create,
|
||||
:format => :json,
|
||||
:person_id => bob.person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
it "succeeds" do
|
||||
post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'creates an aspect membership' do
|
||||
it "creates an aspect membership" do
|
||||
expect {
|
||||
post :create,
|
||||
:format => :json,
|
||||
:person_id => bob.person.id,
|
||||
:aspect_id => @aspect1.id
|
||||
}.to change{
|
||||
post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id
|
||||
}.to change {
|
||||
alice.contact_for(bob.person).aspect_memberships.count
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
it 'creates a contact' do
|
||||
#argggg why?
|
||||
it "creates a contact" do
|
||||
# argggg why?
|
||||
alice.contacts.reload
|
||||
expect {
|
||||
post :create,
|
||||
:format => :json,
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect0.id
|
||||
}.to change{
|
||||
post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
|
||||
}.to change {
|
||||
alice.contacts.size
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
it 'failure flashes error' do
|
||||
it "failure flashes error" do
|
||||
expect(alice).to receive(:share_with).and_return(nil)
|
||||
post :create,
|
||||
:format => :json,
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect0.id
|
||||
post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
|
||||
expect(flash[:error]).not_to be_blank
|
||||
end
|
||||
|
||||
it 'does not 500 on a duplicate key error' do
|
||||
params = {:format => :json, :person_id => @person.id, :aspect_id => @aspect0.id}
|
||||
it "does not 500 on a duplicate key error" do
|
||||
params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id}
|
||||
post :create, params
|
||||
post :create, params
|
||||
expect(response.status).to eq(400)
|
||||
expect(response.body).to include(I18n.t("aspect_memberships.destroy.invalid_statement"))
|
||||
end
|
||||
|
||||
context 'json' do
|
||||
it 'returns the aspect membership' do
|
||||
post :create,
|
||||
:format => :json,
|
||||
:person_id => @person.id,
|
||||
:aspect_id => @aspect0.id
|
||||
context "json" do
|
||||
it "returns the aspect membership" do
|
||||
post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
|
||||
|
||||
contact = @controller.current_user.contact_for(@person)
|
||||
expect(response.body).to eq(AspectMembershipPresenter.new(contact.aspect_memberships.first).base_hash.to_json)
|
||||
|
|
@ -85,26 +71,26 @@ describe AspectMembershipsController, :type => :controller do
|
|||
end
|
||||
|
||||
describe "#destroy" do
|
||||
it 'removes contacts from an aspect' do
|
||||
it "removes contacts from an aspect" do
|
||||
membership = alice.add_contact_to_aspect(@contact, @aspect1)
|
||||
delete :destroy, :format => :json, :id => membership.id
|
||||
delete :destroy, format: :json, id: membership.id
|
||||
expect(response).to be_success
|
||||
@aspect1.reload
|
||||
expect(@aspect1.contacts.to_a).not_to include @contact
|
||||
end
|
||||
|
||||
it 'does not 500 on an html request' do
|
||||
it "does not 500 on an html request" do
|
||||
membership = alice.add_contact_to_aspect(@contact, @aspect1)
|
||||
delete :destroy, :id => membership.id
|
||||
delete :destroy, id: membership.id
|
||||
expect(response).to redirect_to :back
|
||||
@aspect1.reload
|
||||
expect(@aspect1.contacts.to_a).not_to include @contact
|
||||
end
|
||||
|
||||
it 'aspect membership does not exist' do
|
||||
delete :destroy, :format => :json, :id => 123
|
||||
it "aspect membership does not exist" do
|
||||
delete :destroy, format: :json, id: 123
|
||||
expect(response).not_to be_success
|
||||
expect(response.body).to include "Could not find the selected person in that aspect"
|
||||
expect(response.body).to include I18n.t("aspect_memberships.destroy.no_membership")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue