Skip to content

Commit

Permalink
report project and membership when creating metamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Jul 8, 2020
1 parent 263e85e commit a730f1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/meta_models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def create
mm_ope.save!
mda.set_all_parameters_as_decision_variables(ope.analysis.decision_role)
mda.set_owner(current_user)
mda.copy_membership(ope.analysis)

@meta_model = mda.disciplines.last.build_meta_model( # just one plain discipline in the analysis
operation: mm_ope,
Expand Down
5 changes: 4 additions & 1 deletion app/models/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,15 @@ def self.build_metamodel_analysis(ope, varnames = nil)
end
analysis_attrs= {
name: name,
public: ope.analysis.public,
disciplines_attributes: [
{ name: "__DRIVER__", variables_attributes: driver_vars },
{ name: "#{ope.analysis.name.camelize}", type: WhatsOpt::Discipline::METAMODEL,
variables_attributes: metamodel_varattrs }
] }
Analysis.new(analysis_attrs)
mm_mda = Analysis.new(analysis_attrs)
mm_mda.build_design_project_filing(design_project: ope.analysis.design_project) if ope.analysis.design_project
mm_mda
end

def parameterize(parameterization)
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/ownable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def remove_member(user)
end

def copy_membership(ownable_src)
ownable_src.readers.each do |m|
self.add_member(m)
ownable_src.readers.each do |r|
self.add_member(r)
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/controllers/analyses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ class AnalysesControllerTest < ActionDispatch::IntegrationTest
end
copy = Analysis.last
assert_equal @cicav.disciplines.count, copy.disciplines.count

assert_equal user2, copy.owner
assert_equal @cicav.public, copy.public
assert_equal @cicav.design_project, copy.design_project
assert_equal [user1, user3], copy.members # user1 owner of cicav, user3 member of cicav
end
Expand Down
13 changes: 9 additions & 4 deletions test/controllers/api/v1/meta_models_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Api::V1::MetaModelsControllerTest < ActionDispatch::IntegrationTest
setup do
@mda = analyses(:cicav)
@ope = operations(:doe)
@user = users(:user1)
@auth_headers = { "Authorization" => "Token " + @user.api_key }
@user1 = users(:user1)
@auth_headers = { "Authorization" => "Token " + @user1.api_key }
@user2 = users(:user2)
@auth_headers2 = { "Authorization" => "Token " + @user2.api_key }
@user3 = users(:user3)
Expand Down Expand Up @@ -61,14 +61,19 @@ class Api::V1::MetaModelsControllerTest < ActionDispatch::IntegrationTest
assert_difference("Surrogate.count", 1) do
post api_v1_operation_meta_models_url(@ope),
params: { meta_model: { kind: Surrogate::SMT_KPLS } },
as: :json, headers: @auth_headers
as: :json, headers: @auth_headers3
end
end
end
end
# ope = Operation.last
assert_response :success
mda = Analysis.last
assert_equal @user3, mda.owner
assert_equal @mda.public, mda.public
assert_equal @mda.design_project, mda.design_project
assert_equal [@user1], mda.members # user1 owner of cicav

assert_equal 2, mda.design_variables.count
assert_equal 1, mda.response_variables.count
x1 = mda.design_variables.first
Expand All @@ -88,7 +93,7 @@ class Api::V1::MetaModelsControllerTest < ActionDispatch::IntegrationTest
assert_equal surr, mm.surrogates.first
assert_equal mm.default_surrogate_kind, surr.kind
assert_equal(-1, surr.coord_index) # obj is a scalar
assert_equal @user, mm.discipline.analysis.owner
assert_equal @user3, mm.discipline.analysis.owner
end

test "should take into account variables selection" do
Expand Down

0 comments on commit a730f1b

Please sign in to comment.