gooddata 0.6.18 → 0.6.19

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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +8 -19
  4. data/Guardfile +5 -0
  5. data/README.md +1 -3
  6. data/bin/gooddata +1 -1
  7. data/gooddata.gemspec +6 -4
  8. data/lib/gooddata.rb +1 -1
  9. data/lib/gooddata/bricks/middleware/aws_middleware.rb +24 -0
  10. data/lib/gooddata/cli/commands/console_cmd.rb +1 -1
  11. data/lib/gooddata/cli/commands/project_cmd.rb +29 -9
  12. data/lib/gooddata/cli/hooks.rb +9 -3
  13. data/lib/gooddata/commands/datawarehouse.rb +1 -7
  14. data/lib/gooddata/commands/project.rb +4 -3
  15. data/lib/gooddata/core/logging.rb +14 -2
  16. data/lib/gooddata/exceptions/execution_limit_exceeded.rb +9 -0
  17. data/lib/gooddata/exceptions/uncomputable_report.rb +8 -0
  18. data/lib/gooddata/exceptions/validation_error.rb +1 -1
  19. data/lib/gooddata/goodzilla/goodzilla.rb +5 -1
  20. data/lib/gooddata/helpers/data_helper.rb +40 -9
  21. data/lib/gooddata/mixins/md_finders.rb +35 -0
  22. data/lib/gooddata/models/blueprint/anchor_field.rb +46 -0
  23. data/lib/gooddata/models/blueprint/attribute_field.rb +25 -0
  24. data/lib/gooddata/models/blueprint/blueprint.rb +7 -0
  25. data/lib/gooddata/models/blueprint/blueprint_field.rb +66 -0
  26. data/lib/gooddata/models/{dashboard_builder.rb → blueprint/dashboard_builder.rb} +0 -0
  27. data/lib/gooddata/models/{schema_blueprint.rb → blueprint/dataset_blueprint.rb} +176 -117
  28. data/lib/gooddata/models/blueprint/date_dimension.rb +10 -0
  29. data/lib/gooddata/models/blueprint/fact_field.rb +16 -0
  30. data/lib/gooddata/models/blueprint/label_field.rb +39 -0
  31. data/lib/gooddata/models/{project_blueprint.rb → blueprint/project_blueprint.rb} +366 -168
  32. data/lib/gooddata/models/blueprint/project_builder.rb +79 -0
  33. data/lib/gooddata/models/blueprint/reference_field.rb +39 -0
  34. data/lib/gooddata/models/blueprint/schema_blueprint.rb +156 -0
  35. data/lib/gooddata/models/blueprint/schema_builder.rb +85 -0
  36. data/lib/gooddata/models/{to_manifest.rb → blueprint/to_manifest.rb} +25 -20
  37. data/lib/gooddata/models/{to_wire.rb → blueprint/to_wire.rb} +33 -52
  38. data/lib/gooddata/models/datawarehouse.rb +2 -2
  39. data/lib/gooddata/models/domain.rb +3 -2
  40. data/lib/gooddata/models/execution.rb +2 -2
  41. data/lib/gooddata/models/execution_detail.rb +7 -2
  42. data/lib/gooddata/models/from_wire.rb +60 -71
  43. data/lib/gooddata/models/from_wire_parse.rb +125 -125
  44. data/lib/gooddata/models/metadata.rb +14 -0
  45. data/lib/gooddata/models/metadata/dashboard.rb +2 -2
  46. data/lib/gooddata/models/metadata/label.rb +1 -1
  47. data/lib/gooddata/models/metadata/report.rb +6 -5
  48. data/lib/gooddata/models/metadata/report_definition.rb +44 -59
  49. data/lib/gooddata/models/model.rb +131 -43
  50. data/lib/gooddata/models/process.rb +13 -11
  51. data/lib/gooddata/models/profile.rb +12 -1
  52. data/lib/gooddata/models/project.rb +223 -19
  53. data/lib/gooddata/models/project_creator.rb +4 -15
  54. data/lib/gooddata/models/schedule.rb +1 -0
  55. data/lib/gooddata/models/user_filters/user_filter_builder.rb +2 -2
  56. data/lib/gooddata/rest/client.rb +18 -18
  57. data/lib/gooddata/rest/connection.rb +113 -94
  58. data/lib/gooddata/version.rb +1 -1
  59. data/lib/templates/project/model/model.rb.erb +15 -16
  60. data/spec/data/blueprints/additional_dataset_module.json +32 -0
  61. data/spec/data/blueprints/big_blueprint_not_pruned.json +2079 -0
  62. data/spec/data/blueprints/invalid_blueprint.json +103 -0
  63. data/spec/data/blueprints/m_n_model.json +104 -0
  64. data/spec/data/blueprints/model_module.json +25 -0
  65. data/spec/data/blueprints/test_blueprint.json +38 -0
  66. data/spec/data/blueprints/test_project_model_spec.json +106 -0
  67. data/spec/data/gd_gse_data_manifest.json +34 -34
  68. data/spec/data/manifests/test_blueprint.json +32 -0
  69. data/spec/data/{manifest_test_project.json → manifests/test_project.json} +9 -18
  70. data/spec/data/wire_models/test_blueprint.json +63 -0
  71. data/spec/data/wire_test_project.json +5 -5
  72. data/spec/environment/default.rb +33 -0
  73. data/spec/environment/develop.rb +26 -0
  74. data/spec/environment/environment.rb +14 -0
  75. data/spec/environment/hotfix.rb +17 -0
  76. data/spec/environment/production.rb +31 -0
  77. data/spec/environment/release.rb +17 -0
  78. data/spec/helpers/blueprint_helper.rb +10 -7
  79. data/spec/helpers/cli_helper.rb +24 -22
  80. data/spec/helpers/connection_helper.rb +27 -25
  81. data/spec/helpers/crypto_helper.rb +7 -5
  82. data/spec/helpers/csv_helper.rb +5 -3
  83. data/spec/helpers/process_helper.rb +15 -10
  84. data/spec/helpers/project_helper.rb +40 -33
  85. data/spec/helpers/schedule_helper.rb +15 -9
  86. data/spec/helpers/spec_helper.rb +11 -0
  87. data/spec/integration/blueprint_updates_spec.rb +93 -0
  88. data/spec/integration/command_datawarehouse_spec.rb +2 -1
  89. data/spec/integration/command_projects_spec.rb +9 -8
  90. data/spec/integration/create_from_template_spec.rb +1 -1
  91. data/spec/integration/create_project_spec.rb +1 -1
  92. data/spec/integration/full_process_schedule_spec.rb +1 -1
  93. data/spec/integration/full_project_spec.rb +91 -30
  94. data/spec/integration/over_to_user_filters_spec.rb +24 -28
  95. data/spec/integration/partial_md_export_import_spec.rb +4 -4
  96. data/spec/integration/project_spec.rb +1 -1
  97. data/spec/integration/rest_spec.rb +1 -1
  98. data/spec/integration/user_filters_spec.rb +19 -24
  99. data/spec/integration/variables_spec.rb +7 -9
  100. data/spec/logging_in_logging_out_spec.rb +1 -1
  101. data/spec/spec_helper.rb +10 -1
  102. data/spec/unit/bricks/middleware/aws_middelware_spec.rb +47 -0
  103. data/spec/unit/core/connection_spec.rb +2 -2
  104. data/spec/unit/core/logging_spec.rb +12 -4
  105. data/spec/unit/helpers/data_helper_spec.rb +60 -0
  106. data/spec/unit/models/blueprint/attributes_spec.rb +24 -0
  107. data/spec/unit/models/blueprint/dataset_spec.rb +116 -0
  108. data/spec/unit/models/blueprint/labels_spec.rb +39 -0
  109. data/spec/unit/models/blueprint/project_blueprint_spec.rb +643 -0
  110. data/spec/unit/models/blueprint/reference_spec.rb +24 -0
  111. data/spec/unit/models/{schema_builder_spec.rb → blueprint/schema_builder_spec.rb} +12 -4
  112. data/spec/unit/models/blueprint/to_wire_spec.rb +169 -0
  113. data/spec/unit/models/domain_spec.rb +13 -2
  114. data/spec/unit/models/from_wire_spec.rb +277 -98
  115. data/spec/unit/models/metadata_spec.rb +22 -4
  116. data/spec/unit/models/model_spec.rb +49 -39
  117. data/spec/unit/models/profile_spec.rb +1 -0
  118. data/spec/unit/models/project_spec.rb +7 -7
  119. data/spec/unit/models/schedule_spec.rb +20 -0
  120. data/spec/unit/models/to_manifest_spec.rb +31 -11
  121. data/spec/unit/rest/polling_spec.rb +86 -0
  122. metadata +102 -30
  123. data/lib/gooddata/models/project_builder.rb +0 -136
  124. data/lib/gooddata/models/schema_builder.rb +0 -77
  125. data/out.txt +0 -0
  126. data/spec/data/additional_dataset_module.json +0 -18
  127. data/spec/data/blueprint_invalid.json +0 -38
  128. data/spec/data/m_n_model/blueprint.json +0 -76
  129. data/spec/data/model_module.json +0 -18
  130. data/spec/data/test_project_model_spec.json +0 -76
  131. data/spec/unit/models/attribute_column_spec.rb +0 -7
  132. data/spec/unit/models/project_blueprint_spec.rb +0 -239
  133. data/spec/unit/models/to_wire_spec.rb +0 -71
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+ require 'gooddata'
3
+
4
+ describe GoodData::Model::ReferenceBlueprintField do
5
+
6
+ before(:each) do
7
+ @model_view = MultiJson.load(File.read('./spec/data/wire_models/model_view.json'))
8
+ @blueprint = GoodData::Model::FromWire.from_wire(@model_view)
9
+ @dataset = @blueprint.datasets('dataset.opportunityanalysis')
10
+ @attribute = @dataset.attributes('attr.opportunityanalysis.month')
11
+ end
12
+
13
+ describe '#dataset' do
14
+ it 'should return labels on dataset' do
15
+ expect(@dataset.references.first.dataset.id).to eq 'dataset.opp_records'
16
+ end
17
+ end
18
+
19
+ describe '#reference' do
20
+ it 'should return reference on dataset' do
21
+ expect(@dataset.references.first.reference).to eq 'dataset.opp_records'
22
+ end
23
+ end
24
+ end
@@ -6,12 +6,9 @@ require 'gooddata/models/model'
6
6
  describe GoodData::Model::SchemaBuilder do
7
7
 
8
8
  it "should create a schema" do
9
- # pending("Using of humanize")
10
-
11
9
  builder = GoodData::Model::SchemaBuilder.new("a_title")
12
10
  blueprint = builder.to_blueprint
13
- blueprint.title.should == "A Title"
14
- blueprint.name.should == "a_title"
11
+ expect(blueprint.datasets.first.title).to eq 'A Title'
15
12
  end
16
13
 
17
14
  it "should create a schema with some columns" do
@@ -23,4 +20,15 @@ describe GoodData::Model::SchemaBuilder do
23
20
  blueprint.attributes.count == 1
24
21
  end
25
22
 
23
+ it "should be able to create from block" do
24
+ builder = GoodData::Model::SchemaBuilder.create("payments") do |d|
25
+ d.add_attribute('attr.id', :title => 'Id')
26
+ d.add_label('label.id.name', :title => 'Id Name', reference: 'attr.id')
27
+ d.add_fact('amount', :title => 'Amount')
28
+ end
29
+
30
+ blueprint = builder.to_blueprint
31
+ blueprint.attributes.count == 1
32
+ blueprint.facts.count == 1
33
+ end
26
34
  end
@@ -0,0 +1,169 @@
1
+ # encoding: UTF-8
2
+ require 'gooddata'
3
+
4
+ include GoodData::Model
5
+
6
+ describe GoodData::Model::ProjectBlueprint do
7
+
8
+ before(:each) do
9
+ @spec = JSON.parse(File.read("./spec/data/blueprints/big_blueprint_not_pruned.json"), :symbolize_names => true)
10
+ @blueprint = GoodData::Model::ProjectBlueprint.new(@spec)
11
+ @wire_spec = JSON.parse(File.read("./spec/data/wire_models/model_view.json"), :symbolize_names => true)
12
+ end
13
+
14
+ describe '#to_wire' do
15
+ it 'should transform small spec to wire' do
16
+ spec = JSON.parse(File.read("./spec/data/blueprints/test_blueprint.json"), :symbolize_names => true)
17
+ wire_spec = JSON.parse(File.read("./spec/data/wire_models/test_blueprint.json"), :symbolize_names => true)
18
+ res = ToWire.to_wire(spec)
19
+ expect(res).to eq wire_spec
20
+ end
21
+
22
+ it 'it should turn into wire another project' do
23
+ spec = JSON.parse(File.read("./spec/data/blueprints/test_project_model_spec.json"), :symbolize_names => true)
24
+ res = ToWire.to_wire(spec)
25
+ end
26
+
27
+ it 'should create manifest' do
28
+ spec = JSON.parse(File.read("./spec/data/blueprints/test_blueprint.json"), :symbolize_names => true)
29
+ wire_spec = JSON.parse(File.read("./spec/data/wire_models/test_blueprint.json"), :symbolize_names => true)
30
+ manifest_spec = JSON.parse(File.read("./spec/data/manifests/test_blueprint.json"))
31
+ expect(ToWire.to_wire(spec)).to eq wire_spec
32
+ end
33
+ end
34
+
35
+ describe '#anchor_to_wire' do
36
+ it 'should generate anchor without label.' do
37
+ dataset = ProjectBlueprint.find_dataset(@spec, 'dataset.stage_history')
38
+
39
+ result = ToWire.anchor_to_wire(@spec, dataset)
40
+ expect(result).to eq ({
41
+ attribute: {
42
+ identifier: "attr.dataset.stage_history.factsof",
43
+ title: "Records of stage_history",
44
+ folder: "stage_history"}})
45
+ end
46
+
47
+ it 'should generate anchor with label' do
48
+ dataset = ProjectBlueprint.find_dataset(@spec, 'dataset.opportunityanalysis')
49
+ result = ToWire.anchor_to_wire(nil, dataset)
50
+ expect(result).to eq ({
51
+ attribute: {
52
+ :identifier=>"attr.opportunityanalysis.techoppanalysis",
53
+ :title=>"Tech Opp. Analysis",
54
+ :folder=>"Opportunity Benchmark",
55
+ :labels=>[
56
+ {:label=>
57
+ {:identifier=>"label.opportunityanalysis.techoppanalysis",
58
+ :title=>"Tech Opp. Analysis",
59
+ :type=>"GDC.text",
60
+ :dataType=>"VARCHAR(128)"}}],
61
+ :defaultLabel=>"label.opportunityanalysis.techoppanalysis"}})
62
+ end
63
+ end
64
+
65
+ describe '#anchor_to_attribute' do
66
+ it 'should generate attribute without label' do
67
+ dataset = ProjectBlueprint.find_dataset(@spec, 'dataset.stage_history')
68
+ a = DatasetBlueprint.attributes(dataset).find {|a| a[:id] == 'attr.stage_history.currentstatus'}
69
+ result = ToWire.attribute_to_wire(dataset, a)
70
+ expect(result).to eq ({
71
+ :attribute=>
72
+ {:identifier=>"attr.stage_history.currentstatus",
73
+ :title=>"Current Stage",
74
+ :folder=>"stage_history",
75
+ :labels=>
76
+ [{:label=>
77
+ {:identifier=>"label.stage_history.currentstatus",
78
+ :title=>"Current Stage",
79
+ :type=>"GDC.text",
80
+ :dataType=>"VARCHAR(128)"}}],
81
+ :defaultLabel=>"label.stage_history.currentstatus"}})
82
+ end
83
+
84
+ it 'should generate attributes with label' do
85
+ dataset = ProjectBlueprint.find_dataset(@spec, 'dataset.opportunityanalysis')
86
+ a = DatasetBlueprint.attributes(dataset).find {|a| a[:id] == 'attr.opportunityanalysis.month'}
87
+
88
+ result = ToWire.attribute_to_wire(dataset, a)
89
+ expect(result).to eq ({:attribute=>
90
+ {:identifier=>"attr.opportunityanalysis.month",
91
+ :title=>"Month",
92
+ :folder=>"Opportunity Benchmark",
93
+ :labels=>
94
+ [{:label=>
95
+ {:identifier=>"label.opportunityanalysis.month",
96
+ :title=>"Month",
97
+ :type=>"GDC.text",
98
+ :dataType=>"VARCHAR(128)"}},
99
+ {:label=>
100
+ {:identifier=>"label.opportunityanalysis.month.monthsortingnew",
101
+ :title=>"MonthSortingNew",
102
+ :type=>"GDC.text",
103
+ :dataType=>"INT"}}],
104
+ :defaultLabel=>"label.opportunityanalysis.month" }})
105
+ end
106
+ end
107
+
108
+ describe '#fact_to_wire' do
109
+ it 'should generate anchor' do
110
+ fact_def = {
111
+ type: "fact",
112
+ id: "fact.stage_history.stage_velocity",
113
+ title: "Stage Velocity",
114
+ folder: "My Folder",
115
+ description: "Velocity description",
116
+ gd_data_type: "DECIMAL(12,2)"
117
+ }
118
+ result = ToWire.fact_to_wire(nil, fact_def)
119
+ expect(result).to eq ({
120
+ fact: {
121
+ identifier: "fact.stage_history.stage_velocity",
122
+ title: "Stage Velocity",
123
+ dataType: "DECIMAL(12,2)",
124
+ folder: "My Folder",
125
+ description: "Velocity description"}})
126
+ end
127
+ end
128
+
129
+ describe '#references_to_wire' do
130
+ it 'should produce references' do
131
+ dataset = ProjectBlueprint.find_dataset(@spec, 'dataset.opp_snapshot')
132
+ res = ToWire.references_to_wire(@spec, dataset)
133
+ expect(res).to eq [
134
+ "dataset.sdrowner",
135
+ "dataset.leadsourceoriginal",
136
+ "dataset.account",
137
+ "dataset.amounttype",
138
+ "dataset.product",
139
+ "dataset.sourcingorigin",
140
+ "dataset.leadsource",
141
+ "dataset.productline",
142
+ "dataset.stage",
143
+ "dataset.opp_owner",
144
+ "dataset.opportunity",
145
+ "dataset.bookingtype",
146
+ "dataset.forecast",
147
+ "leadcreate",
148
+ "snapshot",
149
+ "oppclose",
150
+ "oppcreated",
151
+ "stage1plus",
152
+ "mqldate",
153
+ "effectivecontractstart",
154
+ "effectivecontractend"
155
+ ]
156
+ end
157
+ end
158
+
159
+ describe '#date_dimension_to_wire' do
160
+ it 'should be able to generate date dimension' do
161
+ res = ToWire.date_dimension_to_wire(@spec, {
162
+ type: "date_dimension",
163
+ id: "timeline",
164
+ title: "Timeline"
165
+ })
166
+ expect(res).to eq({:dateDimension=>{:name=>"timeline", :title=>"Timeline"}})
167
+ end
168
+ end
169
+ end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'gooddata/models/domain'
4
+ require 'gooddata/helpers/csv_helper'
4
5
 
5
6
  describe GoodData::Domain do
6
7
  before(:each) do
@@ -97,19 +98,27 @@ describe GoodData::Domain do
97
98
  end
98
99
 
99
100
  it 'Update a user' do
100
- user = @domain.users.sample
101
+ user = @domain.users.reject { |u| u.login == @client.user.login }.sample
101
102
  login = user.login
102
103
  name = user.first_name
104
+ modes = user.authentication_modes
105
+ possible_modes = [:sso, :password]
106
+
103
107
 
104
108
  user.first_name = name.reverse
109
+ choice = SpecHelper.random_choice(possible_modes, user.authentication_modes)
110
+ user.authentication_modes = choice
105
111
  @domain.create_users([user])
106
112
  changed_user = @domain.get_user(login)
107
113
  expect(changed_user.first_name).to eq name.reverse
114
+ expect(changed_user.authentication_modes).to eq [choice]
108
115
 
109
116
  user.first_name = name
117
+ user.authentication_modes = modes
110
118
  @domain.create_users([user])
111
119
  reverted_user = @domain.get_user(login)
112
120
  expect(reverted_user.first_name).to eq name
121
+ expect(reverted_user.authentication_modes).to eq modes
113
122
  end
114
123
 
115
124
  it 'Fails with an exception if you try to create a user that is in a different domain' do
@@ -121,13 +130,15 @@ describe GoodData::Domain do
121
130
  end
122
131
 
123
132
  it 'updates properties of a profile' do
133
+ pending 'Add more users'
134
+
124
135
  user = @domain.users
125
136
  .reject { |u| u.login == ConnectionHelper::DEFAULT_USERNAME }.sample
126
137
 
127
138
  old_email = user.email
128
139
  old_sso_provider = user.sso_provider || ''
129
140
  user.email = 'john.doe@gooddata.com'
130
- user.sso_provider = user.sso_provider ? user.sso_provider.reverse : 'some_sso_provider'
141
+ user.sso_provider = user.sso_provider.blank? ? user.sso_provider.reverse : 'some_sso_provider'
131
142
  @domain.update_user(user)
132
143
  updated_user = @domain.find_user_by_login(user.login)
133
144
  expect(updated_user.email).to eq 'john.doe@gooddata.com'
@@ -11,125 +11,304 @@ describe GoodData::Model::FromWire do
11
11
  @blueprint = FromWire.from_wire(@model_view)
12
12
  end
13
13
 
14
- it "should parse the model view and return the blueprint" do
15
- expect(@blueprint.datasets.count).to eq 28
16
- end
14
+ describe '#parse_label' do
15
+ it "should be able to parse the attribute" do
16
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'][3]
17
+ a = FromWire.parse_attribute(model['dataset']['attributes'].first['attribute'])
18
+ expect(a.to_set).to eq Set.new([
19
+ {
20
+ type: :attribute,
21
+ id: "attr.opportunityanalysis.month",
22
+ title: "Month",
23
+ folder: "Opportunity Benchmark",
24
+ description: nil,
25
+ },
26
+ {
27
+ type: :label,
28
+ id: "label.opportunityanalysis.month",
29
+ reference: "attr.opportunityanalysis.month",
30
+ title: "Month",
31
+ gd_data_type: "VARCHAR(128)",
32
+ gd_type: "GDC.text",
33
+ default_label: true
34
+ },
35
+ {
36
+ type: :label,
37
+ id: "label.opportunityanalysis.month.monthsortingnew",
38
+ reference: "attr.opportunityanalysis.month",
39
+ title: "MonthSortingNew",
40
+ gd_data_type: "INT",
41
+ gd_type: "GDC.text"
42
+ }])
43
+ end
17
44
 
18
- it "should have a datatype if defined" do
19
- col = @blueprint.find_dataset('stage_history').find_column_by_name('stage_duration', nil)
20
- expect(col.key?(:gd_data_type)).to eq true
21
- expect(col[:gd_data_type]).to eq 'DECIMAL(12,2)'
45
+ it "should be able to parse the anchor" do
46
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'][3]
47
+ x = FromWire.parse_attribute(model['dataset']['anchor']['attribute'], :anchor)
48
+ expect(x.to_set).to eq Set.new([
49
+ {
50
+ type: :anchor,
51
+ id: "attr.opportunityanalysis.techoppanalysis",
52
+ title: "Tech Opp. Analysis",
53
+ folder: "Opportunity Benchmark",
54
+ description: nil,
55
+ },
56
+ {
57
+ type: :label,
58
+ id: "label.opportunityanalysis.techoppanalysis",
59
+ title: "Tech Opp. Analysis",
60
+ reference: "attr.opportunityanalysis.techoppanalysis",
61
+ gd_data_type: "VARCHAR(128)",
62
+ gd_type: "GDC.text",
63
+ default_label: true
64
+ }])
65
+ end
22
66
  end
23
67
 
24
- it "should have a datatype if defined" do
25
- col = @blueprint.find_dataset('stage_history').find_column_by_name('currentstatus', nil)
26
- expect(col.key?(:gd_type)).to eq true
27
- expect(col[:gd_type]).to eq 'GDC.text'
28
- end
68
+ describe '#parse_attributes' do
69
+ it "should be able to parse the attributes with one label" do
70
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'].first
71
+ x = FromWire.parse_attributes(model)
72
+ expect(x.to_set).to eq Set.new([
73
+ {
74
+ type: :attribute,
75
+ id: "attr.stage_history.currentstatus",
76
+ title: "Current Stage",
77
+ description: nil,
78
+ folder: nil
79
+ },
80
+ {
81
+ type: :label,
82
+ id: "label.stage_history.currentstatus",
83
+ reference: "attr.stage_history.currentstatus",
84
+ title: "Current Stage",
85
+ gd_data_type: "VARCHAR(128)",
86
+ gd_type: "GDC.text",
87
+ default_label: true
88
+ }
89
+ ])
90
+ end
29
91
 
30
- it "should validate a gd_datatype" do
31
- expect(GoodData::Model.check_gd_datatype("GDC.time")).to eq true
32
- expect(GoodData::Model.check_gd_datatype("gdc.time")).to eq false
33
- expect(GoodData::Model.check_gd_datatype("gdc.time3")).to eq false
34
- end
92
+ it "should be able to parse the attributes with several labels" do
93
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'][3]
94
+ x = FromWire.parse_attributes(model)
95
+ expect(x.to_set).to eq Set.new([
96
+ {
97
+ type: :attribute,
98
+ id: "attr.opportunityanalysis.month",
99
+ title: "Month",
100
+ description: nil,
101
+ folder: "Opportunity Benchmark"
102
+ },
103
+ {
104
+ type: :label,
105
+ reference: "attr.opportunityanalysis.month",
106
+ id: "label.opportunityanalysis.month",
107
+ title: "Month",
108
+ gd_data_type: "VARCHAR(128)",
109
+ gd_type: "GDC.text",
110
+ default_label: true
111
+ },
112
+ {
113
+ type: :label,
114
+ id: "label.opportunityanalysis.month.monthsortingnew",
115
+ reference: "attr.opportunityanalysis.month",
116
+ title: "MonthSortingNew",
117
+ gd_data_type: "INT",
118
+ gd_type: "GDC.text"
119
+ },
120
+ {
121
+ type: :attribute,
122
+ id: "attr.opportunityanalysis.cohorttype",
123
+ title: "Cohort Type",
124
+ description: nil,
125
+ folder: "Opportunity Benchmark"
126
+ },
127
+ {
128
+ type: :label,
129
+ id: "label.opportunityanalysis.cohorttype",
130
+ reference: "attr.opportunityanalysis.cohorttype",
131
+ title: "Cohort Type",
132
+ gd_data_type: "VARCHAR(128)",
133
+ gd_type: "GDC.text",
134
+ default_label: true
135
+ }
136
+ ])
137
+ end
35
138
 
36
- it "should be able to omit titles if they are superfluous" do
37
- view = MultiJson.load(File.read('./spec/data/superfluous_titles_view.json'))
38
- blueprint = FromWire.from_wire(view)
39
- expect(blueprint.datasets.count).to eq 1
40
- expect(blueprint.datasets.first.find_column_by_name('current_status', nil).key?(:title)).to eq false
41
- expect(blueprint.datasets.mapcat { |ds| ds.columns }.any? {|col| col[:name].titleize == col[:title]}).to eq false
139
+ it "should be able to parse the attributes with no labels" do
140
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'][7]
141
+ x = FromWire.parse_attributes(model)
142
+ expect(x.to_set).to eq Set.new()
143
+ end
42
144
  end
43
145
 
44
- it "should enable sorting" do
45
- skip("UAAA")
146
+ describe '#parse_anchor' do
147
+ it "should be able to parse the anchor without label" do
148
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'].first
149
+ x = FromWire.parse_anchor(model)
150
+ expect(x.to_set).to eq Set.new([{
151
+ type: :anchor,
152
+ id: "attr.stage_history.factsof",
153
+ title: "Records of stage_history",
154
+ description: nil,
155
+ folder: nil
156
+ }])
157
+ end
158
+
159
+ it "should be able to parse the anchor out of dataset when there are multiple labels" do
160
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'][7]
161
+ x = FromWire.parse_anchor(model)
162
+ expect(x.to_set).to eq Set.new([
163
+ {
164
+ type: :anchor,
165
+ id: "attr.opp_records.factsof",
166
+ title: "Records of opp_records",
167
+ description: nil,
168
+ folder: nil
169
+ },
170
+ {
171
+ type: :label,
172
+ id: "label.opp_records.opp_records_conctn_point",
173
+ reference: "attr.opp_records.factsof",
174
+ title: "opp_records_conctn_point",
175
+ gd_data_type: "VARCHAR(128)",
176
+ gd_type: "GDC.text",
177
+ default_label: true
178
+ },
179
+ {
180
+ type: :label,
181
+ id: "label.opp_records.factsof",
182
+ reference: "attr.opp_records.factsof",
183
+ title: "Records of opp_records",
184
+ gd_data_type: "VARCHAR(128)",
185
+ gd_type: "GDC.text"
186
+ }
187
+ ])
188
+ end
189
+
190
+ it 'should' do
191
+ skip('primary vs default. Is it covered?')
192
+ end
46
193
  end
47
194
 
48
- it "should allow defining date dimensions" do
49
- skip('UAAA')
195
+ describe '#parse_facts' do
196
+ it 'should be able to parse facts from dataset' do
197
+ model = @model_view['projectModelView']['model']['projectModel']['datasets'].first
198
+ facts = GoodData::Model::FromWire.parse_facts(model)
199
+ expect(facts.to_set).to eq Set.new([
200
+ {
201
+ type: :fact,
202
+ id: "fact.stage_history.stage_velocity",
203
+ title: "Stage Velocity",
204
+ description: "Velocity description",
205
+ gd_data_type: "DECIMAL(12,2)",
206
+ folder: nil
207
+ },
208
+ {
209
+ type: :fact,
210
+ id: "fact.stage_history.stage_duration",
211
+ title: "Stage Duration",
212
+ gd_data_type: "DECIMAL(12,2)",
213
+ folder: nil
214
+ },
215
+ {
216
+ type: :date_fact,
217
+ id: "dt.stage_history.opp_created_date",
218
+ title: "Opp. Created (Date) for Stage History",
219
+ gd_data_type: "INT",
220
+ folder: nil
221
+ },
222
+ {
223
+ type: :date_fact,
224
+ id: "dt.stage_history.opp_close_date",
225
+ title: "Opp. Close (Date) for Stage History",
226
+ gd_data_type: "INT",
227
+ folder: nil
228
+ }
229
+ ])
230
+ end
50
231
  end
51
232
 
52
- it "should generate the same thing it parsed" do
53
- a = @model_view['projectModelView']['model']['projectModel']['datasets'][3]
54
- b = @blueprint.to_wire
55
- # expect(b).to eq a
233
+ describe '#parse_dataset' do
234
+ it 'should be able to parse dataset' do
235
+ model_view = MultiJson.load(File.read('./spec/data/wire_models/nu_model.json'))
236
+ dataset = GoodData::Model::FromWire.dataset_from_wire(model_view['projectModelView']['model']['projectModel']['datasets'].first)
237
+ expect(dataset).to have_key(:type)
238
+ expect(dataset[:type]).to eq :dataset
239
+ expect(dataset[:id]).to eq 'dataset.bookingsactual'
240
+ expect(dataset[:columns].select { |c| c[:type] == :attribute }.count).to eq 15
241
+ expect(dataset[:columns].select { |c| c[:type] == :fact }.count).to eq 3
242
+ expect(dataset[:columns].select { |c| c[:type] == :reference }.count).to eq 6
243
+ expect(dataset[:columns].select { |c| c[:type] == :date }.count).to eq 5
244
+ end
56
245
  end
57
246
 
58
- it "should be able to parse the anchor out of dataset" do
59
- x = FromWire.parse_anchor(@model_view['projectModelView']['model']['projectModel']['datasets'][3])
60
- expect(x).to eq [
61
- {
62
- type: 'anchor',
63
- name: "techoppanalysis",
64
- folder: "Opportunity Benchmark",
65
- title: "Tech Opp. Analysis",
66
- gd_data_type: "VARCHAR(128)",
67
- gd_type: "GDC.text",
68
- default_label: true
69
- }]
247
+ describe '#from_wire' do
248
+ it 'should be able to parse dataset' do
249
+ model_view = MultiJson.load(File.read('./spec/data/wire_models/nu_model.json'))
250
+ bp = GoodData::Model::FromWire.from_wire(model_view)
251
+ end
70
252
  end
71
253
 
72
- it "should be able to parse the anchor out of dataset" do
73
- x = FromWire.parse_attributes(@model_view['projectModelView']['model']['projectModel']['datasets'][3])
74
- expect(x).to eq [
75
- {
76
- :type=>'attribute',
77
- :folder => "Opportunity Benchmark",
78
- :name=>"month",
79
- :gd_data_type=>"VARCHAR(128)",
80
- :gd_type=>"GDC.text",
81
- :default_label=>true
82
- },
83
- {
84
- :type=>'label',
85
- :reference=>"month",
86
- :name=>"monthsortingnew",
87
- :title=>"MonthSortingNew",
88
- :gd_data_type=>"INT",
89
- :gd_type=>"GDC.text"
90
- },
91
- {
92
- :type=>'attribute',
93
- :folder => "Opportunity Benchmark",
94
- :name=>"cohorttype",
95
- :title=>"Cohort Type",
96
- :gd_data_type=>"VARCHAR(128)",
97
- :gd_type=>"GDC.text",
98
- :default_label=>true
99
- }]
254
+ it "should parse the model view and return the blueprint" do
255
+ expect(@blueprint.datasets.count).to eq 28
100
256
  end
101
257
 
102
- it "should be able to parse the anchor out of dataset when there are multiple labels and primary label and default label are not the same" do
103
- x = FromWire.parse_anchor(@model_view['projectModelView']['model']['projectModel']['datasets'][7])
104
- expect(x).to eq [
105
- {
106
- :type=>"anchor",
107
- :name=>"factsof",
108
- :title=>"Records of opp_records",
109
- :gd_data_type=>"VARCHAR(128)",
110
- :gd_type=>"GDC.text"
111
- },
112
- {
113
- :type=>"label",
114
- :reference=>"factsof",
115
- :name=>"opp_records_conctn_point",
116
- :title=>"opp_records_conctn_point",
117
- :gd_data_type=>"VARCHAR(128)",
118
- :gd_type=>"GDC.text",
119
- :default_label => true
120
- }]
258
+ it "should have a datatype if defined" do
259
+ dataset = @blueprint.datasets.find {|d| d.id == 'dataset.account' }
260
+ dataset.labels_for_attribute('attr.account.accountemployeecount')
261
+
262
+ dataset = @blueprint.find_dataset('dataset.stage_history')
263
+ col = dataset.find_column_by_id('fact.stage_history.stage_duration')
264
+ expect(col.gd_data_type).to eq 'DECIMAL(12,2)'
121
265
  end
122
266
 
123
- it "should be able to parse description from both attributes and facts" do
124
- expect(@blueprint.find_dataset('opportunity').anchor[:description]).to eq 'This is opportunity attribute description'
125
- expect(@blueprint.find_dataset('stage_history').facts.find {|f| f[:name] == 'stage_velocity'}[:description]).to eq 'Velocity description'
126
- expect(@blueprint.find_dataset('opp_owner').attributes.find {|f| f[:name] == 'region'}[:description]).to eq 'Owner Region description'
267
+ it "should have a datatype if defined" do
268
+ col = @blueprint.find_dataset('dataset.stage_history').labels('label.stage_history.currentstatus')
269
+ expect(col.gd_type).to eq 'GDC.text'
127
270
  end
128
271
 
129
- it "should be able to deal with fiscal dimensions with weird names" do
130
- model_view = MultiJson.load(File.read('./spec/data/wire_models/nu_model.json'))
131
- blueprint = FromWire.from_wire(model_view)
132
- blueprint.lint
272
+ it "should validate a gd_type" do
273
+ expect(GoodData::Model.check_gd_type("GDC.time")).to eq true
274
+ expect(GoodData::Model.check_gd_type("gdc.time")).to eq false
275
+ expect(GoodData::Model.check_gd_type("gdc.time3")).to eq false
133
276
  end
134
277
 
278
+ it "should validate a gd_datatype" do
279
+ expect(GoodData::Model.check_gd_data_type("INT")).to eq true
280
+ expect(GoodData::Model.check_gd_data_type("int")).to eq true
281
+ expect(GoodData::Model.check_gd_data_type("VARCHAR(128)")).to eq true
282
+ expect(GoodData::Model.check_gd_data_type("varchar(128)")).to eq true
283
+ expect(GoodData::Model.check_gd_data_type("DECIMAL(10, 5)")).to eq true
284
+ expect(GoodData::Model.check_gd_data_type("DECIMAL(10,5)")).to eq true
285
+ expect(GoodData::Model.check_gd_data_type("DECIMAL(10, 5)")).to eq true
286
+ expect(GoodData::Model.check_gd_data_type("decimal(10, 5)")).to eq true
287
+ expect(GoodData::Model.check_gd_data_type("decimal(10,5)")).to eq true
288
+ expect(GoodData::Model.check_gd_data_type("decimal(10, 5)")).to eq true
289
+ end
290
+ #
291
+ # it "should be able to omit titles if they are superfluous" do
292
+ # view = MultiJson.load(File.read('./spec/data/superfluous_titles_view.json'))
293
+ # blueprint = FromWire.from_wire(view)
294
+ # expect(blueprint.datasets.count).to eq 1
295
+ # expect(blueprint.datasets.first.find_column_by_name('current_status', nil).key?(:title)).to eq false
296
+ # expect(blueprint.datasets.mapcat { |ds| ds.columns }.any? {|col| col[:name].titleize == col[:title]}).to eq false
297
+ # end
298
+ #
299
+ # it "should enable sorting" do
300
+ # skip("UAAA")
301
+ # end
302
+ #
303
+ # it "should generate the same thing it parsed" do
304
+ # a = @model_view['projectModelView']['model']['projectModel']['datasets'][3]
305
+ # b = @blueprint.to_wire
306
+ # # expect(b).to eq a
307
+ # end
308
+ #
309
+ it "should be able to parse description from both attributes and facts" do
310
+ expect(@blueprint.find_dataset('dataset.opportunity').anchor.description).to eq 'This is opportunity attribute description'
311
+ expect(@blueprint.find_dataset('dataset.stage_history').facts.find {|f| f.id == 'fact.stage_history.stage_velocity'}.description).to eq 'Velocity description'
312
+ expect(@blueprint.find_dataset('dataset.opp_owner').attributes.find {|f| f.id == 'attr.opp_owner.region'}.description).to eq 'Owner Region description'
313
+ end
135
314
  end