Skip to content

Commit

Permalink
[MNOE-406] added new approach to use where callback logic with custom…
Browse files Browse the repository at this point in the history
… flag
  • Loading branch information
MAhsenArif committed Feb 23, 2018
1 parent 98c770a commit 0454c4d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ end
# json.connector_version app_instance.oauth_keys[:version]
# end

app_instance.without_tenant = params[:unscoped].present?
app_instance.app.tap do |a|
@apps[app_instance.app_id].first.tap do |a|
json.app_id a.id
json.app_name a.name
json.app_nid a.nid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def index
i.owner = parent_organization
can?(:access,i)
end
ids = @app_instances.collect{ |i| i.app_id }
@apps = MnoEnterprise::App.where('id.in' => ids, unscoped: params[:unscoped].present?).group_by(&:id)
end

# POST /mnoe/jpi/v1/organization/1/app_instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ def partial_hash_for_arrears(arrear)
let(:org_invite) { build(:org_invite, organization: organization) }
let(:app_instance) { build(:app_instance, organization: organization) }
let(:credit_card) { build(:credit_card, organization: organization) }
let(:app) { build(:app)}

before do
organizations = [organization]
allow(organizations).to receive(:loaded?).and_return(true)
allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return(organizations)
allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:app).and_return(app)
api_stub_for(get: "/organizations/#{organization.id}/invoices", response: from_api([invoice]))
api_stub_for(get: "/organizations", response: from_api([organization]))
api_stub_for(get: "/organizations/#{organization.id}", response: from_api(organization))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ module MnoEnterprise
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
# Stub organization + associations
let(:organization) { build(:organization) }
let(:app) { build(:app)}
before { allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return([organization]) }

before { allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:without_tenant).and_return(false) }
before { allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:app).and_return(app) }
let(:app) { build(:app) }

describe 'GET #index' do
let(:app_instance) { build(:app_instance, status: "running") }
Expand All @@ -34,6 +32,11 @@ module MnoEnterprise
allow(app_instances).to receive(:active).and_return(app_instances)
# Updated since last tick
allow(app_instances).to receive(:where).and_return([app_instance])

allow(app_instance).to receive(:app_id).and_return(app.id)

api_stub_for(get: "/apps?filter[id.in][]=#{app.id}&filter[unscoped]=false", response: from_api([app]))
api_stub_for(get: "/apps?filter[id.in]&filter[unscoped]=false", response: from_api(nil))
end

before { sign_in user }
Expand All @@ -52,11 +55,11 @@ module MnoEnterprise
end

context 'with unscoped data' do
before { allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:without_tenant).and_return(true) }
before { api_stub_for(get: "/apps?filter[id.in][]=#{app.id}&filter[unscoped]=true", response: from_api([app])) }
subject { get :index, organization_id: organization.id, timestamp: timestamp, unscoped: true }

it 'retrieved the app instance with the app' do
subject
expect(app_instance.app).to eq(app)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MnoEnterprise
let(:credit_card) { build(:credit_card) }
let(:organization) { build(:organization) }
before do
allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:app).and_return(app)
# allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:app).and_return(app)
api_stub_for(get: "/users/#{user.id}", response: from_api(user))
api_stub_for(get: "/users/#{user.id}/organizations", response: from_api([organization]))
api_stub_for(get: "/organizations/#{organization.id}/app_instances", response: from_api([app_instance]))
Expand Down
7 changes: 4 additions & 3 deletions core/lib/mno_enterprise/concerns/models/app_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module MnoEnterprise::Concerns::Models::AppInstance
# Associations
#==============================================================
belongs_to :owner, class_name: 'MnoEnterprise::Organization'
belongs_to :app, class_name: 'MnoEnterprise::App'

# Define connector_stack?, cloud_stack? etc. methods
[:cube, :cloud, :connector].each do |stackname|
Expand All @@ -64,9 +65,9 @@ module MnoEnterprise::Concerns::Models::AppInstance

scope :active, -> { where('status.in' => ACTIVE_STATUSES) }

def app
MnoEnterprise::App.find(self.app_id, { unscoped: self.without_tenant })
end
# def app
# MnoEnterprise::App.find(self.app_id, { unscoped: self.without_tenant })
# end
end

#==================================================================
Expand Down

0 comments on commit 0454c4d

Please sign in to comment.