gooddata 0.6.51 → 0.6.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +13 -1
  4. data/CONTRIBUTING.md +25 -0
  5. data/PULL_REQUEST_TEMPLATE.md +5 -0
  6. data/README.md +7 -4
  7. data/gooddata.gemspec +2 -3
  8. data/lib/gooddata.rb +1 -0
  9. data/lib/gooddata/bricks/base_downloader.rb +6 -6
  10. data/lib/gooddata/bricks/middleware/aws_middleware.rb +15 -5
  11. data/lib/gooddata/bricks/middleware/dwh_middleware.rb +15 -3
  12. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +13 -4
  13. data/lib/gooddata/bricks/middleware/logger_middleware.rb +3 -0
  14. data/lib/gooddata/exceptions/no_project_error.rb +5 -1
  15. data/lib/gooddata/goodzilla/goodzilla.rb +7 -6
  16. data/lib/gooddata/helpers/data_helper.rb +4 -4
  17. data/lib/gooddata/helpers/global_helpers_params.rb +61 -39
  18. data/lib/gooddata/lcm/actions/apply_custom_maql.rb +9 -0
  19. data/lib/gooddata/lcm/actions/associate_clients.rb +23 -4
  20. data/lib/gooddata/lcm/actions/collect_attrs.rb +56 -0
  21. data/lib/gooddata/lcm/actions/collect_ca_metrics.rb +53 -0
  22. data/lib/gooddata/lcm/actions/collect_clients.rb +25 -3
  23. data/lib/gooddata/lcm/actions/collect_meta.rb +83 -0
  24. data/lib/gooddata/lcm/actions/collect_segment_clients.rb +12 -4
  25. data/lib/gooddata/lcm/actions/collect_segments.rb +4 -4
  26. data/lib/gooddata/lcm/actions/collect_tagged_objects.rb +74 -0
  27. data/lib/gooddata/lcm/actions/create_segment_masters.rb +16 -30
  28. data/lib/gooddata/lcm/actions/ensure_release_table.rb +0 -3
  29. data/lib/gooddata/lcm/actions/ensure_segments.rb +1 -4
  30. data/lib/gooddata/lcm/actions/ensure_technical_users_domain.rb +5 -5
  31. data/lib/gooddata/lcm/actions/ensure_technical_users_project.rb +8 -5
  32. data/lib/gooddata/lcm/actions/hello_world.rb +0 -3
  33. data/lib/gooddata/lcm/actions/import_object_collections.rb +60 -0
  34. data/lib/gooddata/lcm/actions/print_actions.rb +0 -3
  35. data/lib/gooddata/lcm/actions/print_modes.rb +0 -3
  36. data/lib/gooddata/lcm/actions/print_types.rb +1 -4
  37. data/lib/gooddata/lcm/actions/provision_clients.rb +5 -5
  38. data/lib/gooddata/lcm/actions/purge_clients.rb +4 -10
  39. data/lib/gooddata/lcm/actions/segments_filter.rb +0 -6
  40. data/lib/gooddata/lcm/actions/synchronize_attribute_drillpaths.rb +8 -4
  41. data/lib/gooddata/lcm/actions/synchronize_cas.rb +61 -0
  42. data/lib/gooddata/lcm/actions/synchronize_clients.rb +9 -3
  43. data/lib/gooddata/lcm/actions/synchronize_color_palette.rb +13 -5
  44. data/lib/gooddata/lcm/actions/synchronize_etls_in_segment.rb +71 -17
  45. data/lib/gooddata/lcm/actions/synchronize_label_types.rb +8 -5
  46. data/lib/gooddata/lcm/actions/synchronize_ldm.rb +17 -8
  47. data/lib/gooddata/lcm/actions/synchronize_meta.rb +0 -3
  48. data/lib/gooddata/lcm/actions/synchronize_new_segments.rb +9 -4
  49. data/lib/gooddata/lcm/actions/synchronize_processes.rb +9 -5
  50. data/lib/gooddata/lcm/actions/synchronize_schedules.rb +15 -5
  51. data/lib/gooddata/lcm/actions/synchronize_tag_objects.rb +61 -0
  52. data/lib/gooddata/lcm/actions/update_release_table.rb +0 -3
  53. data/lib/gooddata/lcm/helpers/tags_helper.rb +35 -0
  54. data/lib/gooddata/lcm/lcm.rb +22 -4
  55. data/lib/gooddata/lcm/lcm2.rb +66 -13
  56. data/lib/gooddata/lcm/types/complex/update_preference.rb +1 -1
  57. data/lib/gooddata/mixins/md_finders.rb +4 -2
  58. data/lib/gooddata/mixins/md_object_indexer.rb +13 -3
  59. data/lib/gooddata/mixins/md_object_query.rb +8 -2
  60. data/lib/gooddata/models/blueprint/date_dimension.rb +6 -0
  61. data/lib/gooddata/models/blueprint/project_blueprint.rb +41 -11
  62. data/lib/gooddata/models/blueprint/project_builder.rb +20 -0
  63. data/lib/gooddata/models/blueprint/to_wire.rb +7 -0
  64. data/lib/gooddata/models/client.rb +6 -0
  65. data/lib/gooddata/models/domain.rb +6 -6
  66. data/lib/gooddata/models/from_wire.rb +5 -1
  67. data/lib/gooddata/models/metadata.rb +55 -9
  68. data/lib/gooddata/models/metadata/attribute.rb +19 -4
  69. data/lib/gooddata/models/metadata/dashboard.rb +15 -3
  70. data/lib/gooddata/models/metadata/dataset.rb +5 -2
  71. data/lib/gooddata/models/metadata/dimension.rb +4 -1
  72. data/lib/gooddata/models/metadata/fact.rb +9 -2
  73. data/lib/gooddata/models/metadata/folder.rb +4 -1
  74. data/lib/gooddata/models/metadata/metric.rb +11 -3
  75. data/lib/gooddata/models/metadata/report.rb +7 -2
  76. data/lib/gooddata/models/metadata/report_definition.rb +11 -4
  77. data/lib/gooddata/models/metadata/scheduled_mail.rb +4 -1
  78. data/lib/gooddata/models/metadata/variable.rb +7 -2
  79. data/lib/gooddata/models/model.rb +14 -3
  80. data/lib/gooddata/models/process.rb +10 -9
  81. data/lib/gooddata/models/project.rb +134 -36
  82. data/lib/gooddata/models/project_creator.rb +43 -20
  83. data/lib/gooddata/models/report_data_result.rb +6 -2
  84. data/lib/gooddata/models/schedule.rb +6 -3
  85. data/lib/gooddata/models/subscription.rb +8 -1
  86. data/lib/gooddata/models/user_filters/user_filter.rb +1 -0
  87. data/lib/gooddata/models/user_filters/user_filter_builder.rb +18 -4
  88. data/lib/gooddata/models/user_filters/variable_user_filter.rb +3 -1
  89. data/lib/gooddata/rest/client.rb +4 -6
  90. data/lib/gooddata/rest/connection.rb +10 -2
  91. data/lib/gooddata/version.rb +1 -1
  92. data/spec/data/blueprints/test_blueprint.json +1 -0
  93. data/spec/data/wire_models/test_blueprint.json +3 -0
  94. data/spec/data/workspace_table.csv +3 -0
  95. data/spec/environment/development.rb +4 -1
  96. data/spec/environment/environment.rb +1 -1
  97. data/spec/environment/staging.rb +5 -1
  98. data/spec/environment/testing.rb +5 -2
  99. data/spec/integration/blueprint_with_ca_spec.rb +56 -0
  100. data/spec/integration/clients_spec.rb +21 -0
  101. data/spec/integration/command_datawarehouse_spec.rb +7 -1
  102. data/spec/integration/create_from_template_spec.rb +9 -3
  103. data/spec/integration/project_spec.rb +7 -0
  104. data/spec/integration/segments_spec.rb +0 -53
  105. data/spec/integration/subscription_spec.rb +29 -4
  106. data/spec/integration/urn_date_dim_spec.rb +53 -0
  107. data/spec/integration/user_filters_spec.rb +6 -0
  108. data/spec/integration/variables_spec.rb +1 -2
  109. data/spec/spec_helper.rb +5 -30
  110. data/spec/unit/actions/collect_clients_spec.rb +38 -0
  111. data/spec/unit/actions/collect_meta_spec.rb +87 -0
  112. data/spec/unit/actions/collect_segment_clients_spec.rb +40 -0
  113. data/spec/unit/actions/collect_tagged_objects_spec.rb +110 -0
  114. data/spec/unit/actions/synchronize_etls_in_segment_spec.rb +51 -0
  115. data/spec/unit/bricks/middleware/aws_middelware_spec.rb +55 -1
  116. data/spec/unit/bricks/middleware/logger_middleware_spec.rb +15 -0
  117. data/spec/unit/helpers/data_helper_spec.rb +3 -5
  118. data/spec/unit/helpers/global_helpers_spec.rb +29 -0
  119. data/spec/unit/helpers_spec.rb +18 -1
  120. data/spec/unit/models/blueprint/project_blueprint_spec.rb +1 -23
  121. data/spec/unit/models/domain_spec.rb +19 -0
  122. data/spec/unit/models/metadata_spec.rb +34 -0
  123. data/spec/unit/models/schedule_spec.rb +31 -0
  124. data/spec/unit/models/to_manifest_spec.rb +10 -2
  125. data/spec/unit/models/unit_project_spec.rb +6 -1
  126. data/spec/unit/rest/polling_spec.rb +13 -1
  127. metadata +49 -31
@@ -21,7 +21,14 @@ describe GoodData::Subscription, :constraint => 'slow' do
21
21
 
22
22
  it 'should be able to create a subscription' do
23
23
  begin
24
- subscription = GoodData::Subscription.create(client: @client, project: ProjectHelper::PROJECT_ID, channels: @channel, message: 'hello world', process: ProcessHelper::PROCESS_ID, project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT)
24
+ subscription = GoodData::Subscription.create(
25
+ client: @client,
26
+ project: ProjectHelper::PROJECT_ID,
27
+ channels: @channel,
28
+ message: 'hello world',
29
+ process: ProcessHelper::PROCESS_ID,
30
+ project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT
31
+ )
25
32
  expect(subscription.title).to eq ConnectionHelper::DEFAULT_USERNAME
26
33
  expect(subscription.channels).to eq [@channel.uri]
27
34
  expect(subscription.message).to eq 'hello world'
@@ -34,7 +41,13 @@ describe GoodData::Subscription, :constraint => 'slow' do
34
41
 
35
42
  it 'should be able to edit a subscription' do
36
43
  begin
37
- subscription = GoodData::Subscription.create(client: @client, project: ProjectHelper::PROJECT_ID, channels: @channel, process: ProcessHelper::PROCESS_ID, project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT)
44
+ subscription = GoodData::Subscription.create(
45
+ client: @client,
46
+ project: ProjectHelper::PROJECT_ID,
47
+ channels: @channel,
48
+ process: ProcessHelper::PROCESS_ID,
49
+ project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT
50
+ )
38
51
  expect(subscription.title).to eq ConnectionHelper::DEFAULT_USERNAME
39
52
 
40
53
  subscription.title = 'My title'
@@ -49,7 +62,13 @@ describe GoodData::Subscription, :constraint => 'slow' do
49
62
  it 'should be able to list all subscriptions' do
50
63
  begin
51
64
  expect(GoodData::Subscription.all(project: ProjectHelper::PROJECT_ID, client: @client)).to eq []
52
- subscription = GoodData::Subscription.create(client: @client, project: ProjectHelper::PROJECT_ID, channels: @channel, process: ProcessHelper::PROCESS_ID, project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT)
65
+ subscription = GoodData::Subscription.create(
66
+ client: @client,
67
+ project: ProjectHelper::PROJECT_ID,
68
+ channels: @channel,
69
+ process: ProcessHelper::PROCESS_ID,
70
+ project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT
71
+ )
53
72
  expect(GoodData::Subscription.all(project: ProjectHelper::PROJECT_ID, client: @client)).to eq [subscription]
54
73
  ensure
55
74
  subscription && subscription.delete
@@ -57,7 +76,13 @@ describe GoodData::Subscription, :constraint => 'slow' do
57
76
  end
58
77
 
59
78
  it 'should be able to delete a subscription' do
60
- subscription = GoodData::Subscription.create(client: @client, project: ProjectHelper::PROJECT_ID, channels: @channel, process: ProcessHelper::PROCESS_ID, project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT)
79
+ subscription = GoodData::Subscription.create(
80
+ client: @client,
81
+ project: ProjectHelper::PROJECT_ID,
82
+ channels: @channel,
83
+ process: ProcessHelper::PROCESS_ID,
84
+ project_events: GoodData::Subscription::PROCESS_SUCCESS_EVENT
85
+ )
61
86
  subscription.delete
62
87
  end
63
88
  end
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'gooddata'
8
+
9
+ describe "Blueprint now support urn in date dimension", :constraint => 'slow' do
10
+ before(:all) do
11
+ @client = ConnectionHelper.create_default_connection
12
+
13
+ @blueprint = GoodData::Model::ProjectBlueprint.build("My project from blueprint") do |p|
14
+ p.add_date_dimension('created_on', urn: 'urn:pe:date')
15
+ end
16
+ end
17
+
18
+ after(:all) do
19
+ @client && @client.disconnect
20
+ end
21
+
22
+ context 'project creates from blueprint contains urn in date dimension' do
23
+ before(:all) do
24
+ @project = @client.create_project_from_blueprint(@blueprint, token: ConnectionHelper::GD_PROJECT_TOKEN, environment: ProjectHelper::ENVIRONMENT)
25
+ end
26
+
27
+ after(:all) do
28
+ @project && @project.delete
29
+ end
30
+
31
+ it 'should have urn in date dimension' do
32
+ expect(@project.datasets.find(&:date_dimension?).content['urn']).to eq 'urn:pe:date'
33
+ end
34
+
35
+ it 'blueprint contains urn in date dimension' do
36
+ expect(@project.blueprint.date_dimensions.first.urn).to eq 'urn:pe:date'
37
+ end
38
+ end
39
+
40
+ context 'merging blueprint' do
41
+ before do
42
+ @new_bp = GoodData::Model::ProjectBlueprint.build("update") do |p|
43
+ p.add_date_dimension('created_on', urn: 'urn:stonegate:date')
44
+ end
45
+
46
+ @blueprint = @blueprint.merge(@new_bp)
47
+ end
48
+
49
+ it 'update urn' do
50
+ expect(@blueprint.date_dimensions.first.urn).to eq 'urn:stonegate:date'
51
+ end
52
+ end
53
+ end
@@ -133,6 +133,12 @@ describe "User filters implementation", :constraint => 'slow' do
133
133
  expect(@project.data_permissions.count).to eq 0
134
134
  end
135
135
 
136
+ it 'should drop the filter when none of filter values is found' do
137
+ filters = [[ConnectionHelper::DEFAULT_USERNAME, @label.uri, '%^&*( nonexistent value']]
138
+ @project.add_data_permissions(filters, ignore_missing_values: true)
139
+ expect(@project.data_permissions.count).to eq 0
140
+ end
141
+
136
142
  it "should add a filter with nonexistent values when asked" do
137
143
  filters = [[ConnectionHelper::DEFAULT_USERNAME, @label.uri, '%^&*( nonexistent value', 'jirka@gooddata.com']]
138
144
  @project.add_data_permissions(filters, ignore_missing_values: true)
@@ -146,8 +146,7 @@ describe "Variables implementation", :constraint => 'slow' do
146
146
  filters = [[ConnectionHelper::DEFAULT_USERNAME, @label.uri, "NONEXISTENT1", "NONEXISTENT2", "NONEXISTENT3"]]
147
147
  @project.add_variable_permissions(filters, @variable, ignore_missing_values: true)
148
148
  # expect(metric.execute).to eq 9
149
- expect(@variable.user_values.map { |f| [f.related.login, f.pretty_expression] })
150
- .to eq [[ConnectionHelper::DEFAULT_USERNAME, "TRUE"]]
149
+ expect(@variable.user_values.count).to eq 0
151
150
 
152
151
  @project.add_variable_permissions(filters, @variable, ignore_missing_values: true, restrict_if_missing_all_values: true)
153
152
  # expect(metric.execute).to eq nil
@@ -9,6 +9,11 @@ require 'pmap'
9
9
  require 'rspec'
10
10
  require 'pathname'
11
11
  require 'webmock/rspec'
12
+ require 'gooddata'
13
+
14
+ logger = Logger.new(STDOUT)
15
+ logger.level = Logger::WARN
16
+ GoodData.logger = logger
12
17
 
13
18
  WebMock.disable!
14
19
 
@@ -43,36 +48,6 @@ RSpec.configure do |config|
43
48
  config.filter_run_excluding :broken => true
44
49
 
45
50
  config.fail_fast = false
46
-
47
- config.before(:all) do
48
- # TODO: Move this to some method.
49
- # TODO Make more intelligent so two test suites can run at the same time.
50
- # ConnectionHelper.create_default_connection
51
- # users = GoodData::Domain.users(ConnectionHelper::DEFAULT_DOMAIN)
52
- # users.pmap do |user|
53
- # user.delete if user.email != ConnectionHelper::DEFAULT_USERNAME
54
- # end
55
-
56
- # TODO: Fully setup global environment
57
- # $stdout.sync=true
58
- # $stderr.sync=true
59
-
60
- GoodData.logging_off
61
- GoodData.stats_off
62
- end
63
-
64
- config.after(:all) do
65
- # TODO: Fully setup global environment
66
- end
67
-
68
- config.before(:suite) do
69
- # TODO: Setup test project
70
- GoodData.logging_off
71
- end
72
-
73
- config.after(:suite) do
74
- # TODO: Delete test project
75
- end
76
51
  end
77
52
 
78
53
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'gooddata/lcm/actions/collect_clients'
8
+ require 'gooddata/lcm/lcm2'
9
+
10
+ describe GoodData::LCM2::CollectClients do
11
+ let(:data_source) { double(:data_source) }
12
+ let(:input_data) { double(:input_data) }
13
+
14
+ before do
15
+ allow(GoodData::Helpers::DataSource).to receive(:new)
16
+ .and_return(data_source)
17
+ allow(data_source).to receive(:realize)
18
+ .and_return('spec/data/workspace_table.csv')
19
+ end
20
+
21
+ context 'when segments is specified' do
22
+ let(:params) do
23
+ params = {
24
+ segments: [{ segment_id: 'segment_foo' }],
25
+ input_source: {}
26
+ }
27
+ GoodData::LCM2.convert_to_smart_hash(params)
28
+ end
29
+
30
+ it 'collects all clients' do
31
+ result = subject.class.call(params)
32
+ expected = [{ client: 'client_foo',
33
+ segment_id: 'segment_foo',
34
+ title: nil }]
35
+ expect(result[:results]).to eq(expected)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'gooddata/lcm/actions/collect_meta'
8
+ require 'gooddata/lcm/lcm2'
9
+
10
+ describe GoodData::LCM2::CollectMeta do
11
+ let(:development_client) { double('development_client') }
12
+ let(:dashboard) { double('dashboard', uri: 'tagged/dashboard/uri') }
13
+
14
+ before do
15
+ allow(development_client).to receive(:projects).and_return({})
16
+ end
17
+
18
+ context 'when no production tag configured' do
19
+ let(:params) do
20
+ params = {
21
+ development_client: development_client,
22
+ synchronize: [{ from: 'project_id' }]
23
+ }
24
+ GoodData::LCM2.convert_to_smart_hash(params)
25
+ end
26
+
27
+ it 'retrieves all dashboards' do
28
+ expect(GoodData::Dashboard).to receive(:all).and_return({})
29
+ subject.class.call(params)
30
+ end
31
+ end
32
+
33
+ context 'when global production tag configured' do
34
+ let(:params) do
35
+ params = {
36
+ development_client: development_client,
37
+ synchronize: [{ from: 'project_id' }],
38
+ production_tag: 'production_tag'
39
+ }
40
+ GoodData::LCM2.convert_to_smart_hash(params)
41
+ end
42
+
43
+ it 'retrieves dashboards by the specified tag' do
44
+ expect(GoodData::Dashboard).to receive(:find_by_tag)
45
+ .with(['production_tag'], any_args)
46
+ .and_return({})
47
+ subject.class.call(params)
48
+ end
49
+ end
50
+
51
+ context 'when segment-specific production tag configured' do
52
+ let(:params) do
53
+ params = {
54
+ development_client: development_client,
55
+ synchronize: [{ from: 'project_id' }],
56
+ segments: [{ production_tag: 'segment_production_tag' }, {}]
57
+ }
58
+ GoodData::LCM2.convert_to_smart_hash(params)
59
+ end
60
+
61
+ it 'retrieves dashboards by the specified tag' do
62
+ expect(GoodData::Dashboard).to receive(:find_by_tag)
63
+ .with(['segment_production_tag'], any_args)
64
+ .and_return({})
65
+ subject.class.call(params)
66
+ end
67
+ end
68
+
69
+ context 'when both global and segment-specific production tags configured' do
70
+ let(:params) do
71
+ params = {
72
+ development_client: development_client,
73
+ synchronize: [{ from: 'project_id' }],
74
+ segments: [{ production_tag: 'segment_production_tag' }, {}],
75
+ production_tag: 'production_tag'
76
+ }
77
+ GoodData::LCM2.convert_to_smart_hash(params)
78
+ end
79
+
80
+ it 'preffers segment-specific tags' do
81
+ expect(GoodData::Dashboard).to receive(:find_by_tag)
82
+ .with(%w(segment_production_tag), any_args)
83
+ .and_return({})
84
+ subject.class.call(params)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'gooddata/lcm/actions/collect_segment_clients'
8
+ require 'gooddata/lcm/lcm2'
9
+
10
+ describe GoodData::LCM2::CollectSegmentClients do
11
+ let(:gdc_gd_client) { double('gdc_gd_client') }
12
+ let(:domain) { double('domain') }
13
+ let(:segment) { double('segment') }
14
+ let(:segments) { [segment] }
15
+ let(:client) { double('client') }
16
+ let(:clients) { [client] }
17
+
18
+ context 'when client has no project in segments' do
19
+ let(:params) do
20
+ params = {
21
+ gdc_gd_client: gdc_gd_client,
22
+ synchronize: [{}],
23
+ segments: [{}]
24
+ }
25
+ GoodData::LCM2.convert_to_smart_hash(params)
26
+ end
27
+
28
+ before do
29
+ allow(gdc_gd_client).to receive(:domain).and_return(domain)
30
+ allow(domain).to receive(:segments).and_return(segments)
31
+ allow(segment).to receive(:clients).and_return(clients)
32
+ allow(client).to receive(:project?).and_return(false)
33
+ allow(client).to receive(:client_id).and_return('my_client_id')
34
+ end
35
+
36
+ it 'raise error' do
37
+ expect { subject.class.call(params) }.to raise_error
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'gooddata/lcm/actions/collect_tagged_objects'
8
+ require 'gooddata/lcm/lcm2'
9
+
10
+ shared_examples 'a tagged object collector' do
11
+ it 'collects tagged objects' do
12
+ result = subject.class.call(params)
13
+ expected = {
14
+ results: [{ project: 'some_development_project_id',
15
+ transfer_uri: 'tagged1' },
16
+ { project: 'some_development_project_id',
17
+ transfer_uri: 'tagged2' }],
18
+ params: {
19
+ synchronize: [{
20
+ from: 'some_development_project_id',
21
+ transfer_uris: tagged_objects
22
+ }]
23
+ }
24
+ }
25
+ expect(result).to eq(expected)
26
+ end
27
+
28
+ it 'finds projects by the specified tags' do
29
+ expect(development_project).to receive(:find_by_tag)
30
+ .with(['production_tag'])
31
+ subject.class.call(params)
32
+ end
33
+ end
34
+
35
+ describe GoodData::LCM2::CollectTaggedObjects do
36
+ let(:development_client) { double('development_client') }
37
+
38
+ context 'when no production tags configured' do
39
+ let(:params) do
40
+ params = {
41
+ development_client: development_client,
42
+ synchronize: [{}],
43
+ segments: [{}]
44
+ }
45
+ GoodData::LCM2.convert_to_smart_hash(params)
46
+ end
47
+
48
+ before do
49
+ allow(development_client).to receive(:projects).and_return({})
50
+ end
51
+
52
+ it 'returns an empty array' do
53
+ result = subject.class.call(params)
54
+ expect(result).to be_empty
55
+ end
56
+ end
57
+
58
+ context 'when global production tags configured' do
59
+ let(:tagged_objects) { %w(tagged1 tagged2) }
60
+ let(:development_project) { double('development_project') }
61
+
62
+ before do
63
+ allow(development_project).to receive(:find_by_tag)
64
+ .and_return(tagged_objects)
65
+ allow(development_client).to receive(:projects)
66
+ .and_return(development_project)
67
+ end
68
+
69
+ context 'when segment-specific production tags specified' do
70
+ let(:params) do
71
+ params = {
72
+ development_client: development_client,
73
+ synchronize: [{ from: 'some_development_project_id' }],
74
+ segments: [{ production_tag: 'production_tag' }, {}]
75
+ }
76
+ GoodData::LCM2.convert_to_smart_hash(params)
77
+ end
78
+
79
+ it_behaves_like 'a tagged object collector'
80
+ end
81
+
82
+ context 'when global production tags specified' do
83
+ let(:params) do
84
+ params = {
85
+ development_client: development_client,
86
+ synchronize: [{ from: 'some_development_project_id' }],
87
+ segments: [{}],
88
+ production_tag: 'production_tag'
89
+ }
90
+ GoodData::LCM2.convert_to_smart_hash(params)
91
+ end
92
+
93
+ it_behaves_like 'a tagged object collector'
94
+ end
95
+
96
+ context 'when both global and segment-specific production tags specified' do
97
+ let(:params) do
98
+ params = {
99
+ development_client: development_client,
100
+ synchronize: [{ from: 'some_development_project_id' }],
101
+ segments: [{ production_tag: 'production_tag' }, {}],
102
+ production_tag: 'global_production_tag'
103
+ }
104
+ GoodData::LCM2.convert_to_smart_hash(params)
105
+ end
106
+
107
+ it_behaves_like 'a tagged object collector'
108
+ end
109
+ end
110
+ end