Skip to content

Commit

Permalink
Apply code review comments
Browse files Browse the repository at this point in the history
- fix issue with provisioning + update spec
- Add log warning in has_one in test and development
  • Loading branch information
x4d3 committed Nov 27, 2017
1 parent 666a7cd commit 0c97737
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def index
# GET /mnoe/jpi/v1/admin/impac/dashboard_templates/1
def show
@dashboard_template = MnoEnterprise::Dashboard.find_one!(params[:id], *DASHBOARD_DEPENDENCIES)
load_organizations
end

# POST /mnoe/jpi/v1/admin/impac/dashboard_templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ def update_app_list
if params[:organization].key?(:app_nids) && (desired_nids = Array(params[:organization][:app_nids]))
existing_apps = @organization.app_instances&.select(&:active?) || []
existing_apps.each { |app_instance| desired_nids.delete(app_instance.app.nid) || app_instance.terminate }
desired_nids.each { |nid| @organization.provision_app_instance!(nid) }
desired_nids.each do |nid|
MnoEnterprise::AppInstance.provision!(nid, @organization.id, 'Organization' )
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ def app_relation(org_id = nil)

# Return the organization_id passed as query parameters if the current_user has access to it
def app_instance_organization_id
return params[:organization_id] if current_user && params[:organization_id].presence && orga_relation
return params[:organization_id] if current_user && params[:organization_id].presence && orga_relation_id
end

def orga_relation
MnoEnterprise::OrgaRelation.where('user.id' => current_user.id, 'organization.id': params[:organization_id]).first
def orga_relation_id
MnoEnterprise::OrgaRelation.where('user.id': current_user.id, 'organization.id': params[:organization_id]).select(:id).first&.id
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ module MnoEnterprise

describe 'app provisioning' do
let(:params) { attributes_for(:organization).merge(app_nids: ['xero', app_instance.app.nid]) }

before { expect_any_instance_of(Organization).to receive(:provision_app_instance!) }
let!(:provisionning_stub) { stub_api_v2(:post, '/app_instances/provision')}
before { subject }
it { expect(data['organization']['id']).to eq(organization.id) }
it { expect(provisionning_stub).to have_been_requested }
end
end

Expand All @@ -130,7 +130,7 @@ module MnoEnterprise
let(:orga_invite) { build(:orga_invite) }

before { allow(orga_invite).to receive(:user).and_return(invited_user) }
before { stub_api_v2(:get, '/users', invited_user, [:orga_relations], { filter: { email: params[:email] }, page: { number: 1, size: 1 } }) }
before { stub_api_v2(:get, '/users', invited_user, [:orga_relations], { filter: { email: params[:email] }, page: one_page }) }
before { stub_api_v2(:get, "/orga_invites/#{orga_invite.id}", orga_invite, [:user]) }
before { expect(MnoEnterprise::OrgaInvite).to receive(:create).and_return(orga_invite) }
before { subject }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def hash_for_apps(apps)
before do
sign_in(user)
stub_api_v2(:get, "/organizations", [organization], [], { fields: { organizations: 'id' }, filter: { id: organization.id, 'users.id' => user.id }, page: one_page })
stub_orga_relation(user, organization, orga_relation)
stub_api_v2(:get, '/orga_relations', [orga_relation], [], { fields: { orga_relations: 'id' }, filter: { 'user.id': user.id, 'organization.id': organization.id }, page: one_page })

stub_api_v2(:get, '/apps', [app], DEPENDENCIES, { _metadata: { organization_id: organization.id }, filter: { active: true } })
stub_api_v2(:get, '/apps', [app], [],
{
Expand Down
9 changes: 4 additions & 5 deletions core/lib/json_api_client_extension/has_one_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module JsonApiClientExtension::HasOneExtension

class_methods do
def has_one(attr_name, options = {})
setter_log_warning = (Rails.env.test? || Rails.env.development?) ? "ActiveSupport::Deprecation.warn('#{self.name}.#{attr_name}_id= Use relationships instead')" : ''
getter_log_warning = (Rails.env.test? || Rails.env.development?) ? "ActiveSupport::Deprecation.warn('#{self.name}.#{attr_name}_id Use relationships instead')" : ''
class_eval <<-CODE
def #{attr_name}_id=(id)
# Uncomment when doing refactoring
# ActiveSupport::Deprecation.warn(self.class.name + ".#{attr_name}_id= Use relationships instead")
#{setter_log_warning}
super
end
def #{attr_name}_id
# Uncomment when doing refactoringgit
# ActiveSupport::Deprecation.warn(self.class.name + ".#{attr_name}_id Use relationships instead")
#{getter_log_warning}
super
end
def #{attr_name}=(relation)
Expand All @@ -21,7 +21,6 @@ def #{attr_name}=(relation)
def #{attr_name}
relations[:#{attr_name}] ||= super
end
CODE
super
end
Expand Down

0 comments on commit 0c97737

Please sign in to comment.