gooddata 0.6.7 → 0.6.8

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 (145) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -1
  3. data/README.md +10 -2
  4. data/TODO.md +32 -0
  5. data/gooddata.gemspec +5 -0
  6. data/lib/gooddata.rb +4 -0
  7. data/lib/gooddata/app/app.rb +12 -0
  8. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +4 -3
  9. data/lib/gooddata/bricks/middleware/restforce_middleware.rb +2 -1
  10. data/lib/gooddata/cli/commands/console_cmd.rb +23 -5
  11. data/lib/gooddata/cli/commands/domain_cmd.rb +9 -10
  12. data/lib/gooddata/cli/commands/process_cmd.rb +11 -9
  13. data/lib/gooddata/cli/commands/project_cmd.rb +25 -27
  14. data/lib/gooddata/cli/commands/projects_cmd.rb +2 -2
  15. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +1 -1
  16. data/lib/gooddata/cli/commands/user_cmd.rb +2 -2
  17. data/lib/gooddata/cli/hooks.rb +4 -2
  18. data/lib/gooddata/cli/shared.rb +1 -1
  19. data/lib/gooddata/cli/terminal.rb +1 -1
  20. data/lib/gooddata/commands/api.rb +1 -1
  21. data/lib/gooddata/commands/auth.rb +4 -28
  22. data/lib/gooddata/commands/domain.rb +9 -4
  23. data/lib/gooddata/commands/process.rb +26 -23
  24. data/lib/gooddata/commands/project.rb +74 -50
  25. data/lib/gooddata/commands/projects.rb +3 -2
  26. data/lib/gooddata/commands/role.rb +9 -3
  27. data/lib/gooddata/commands/user.rb +6 -4
  28. data/lib/gooddata/connection.rb +11 -45
  29. data/lib/gooddata/core/logging.rb +0 -1
  30. data/lib/gooddata/core/project.rb +22 -22
  31. data/lib/gooddata/core/rest.rb +9 -8
  32. data/lib/gooddata/core/user.rb +0 -11
  33. data/lib/gooddata/exceptions/project_not_found.rb +1 -0
  34. data/lib/gooddata/extensions/enumerable.rb +10 -0
  35. data/lib/gooddata/extensions/hash.rb +25 -0
  36. data/lib/gooddata/goodzilla/goodzilla.rb +4 -4
  37. data/lib/gooddata/helper/class_helper.rb +1 -0
  38. data/lib/gooddata/helper/helpers.rb +8 -0
  39. data/lib/gooddata/helpers/auth_helpers.rb +41 -0
  40. data/lib/gooddata/mixins/author.rb +1 -1
  41. data/lib/gooddata/mixins/contributor.rb +1 -1
  42. data/lib/gooddata/mixins/data_property_reader.rb +2 -0
  43. data/lib/gooddata/mixins/data_property_writer.rb +2 -0
  44. data/lib/gooddata/mixins/inspector.rb +49 -0
  45. data/lib/gooddata/mixins/md_finders.rb +16 -8
  46. data/lib/gooddata/mixins/md_id_to_uri.rb +12 -4
  47. data/lib/gooddata/mixins/md_object_indexer.rb +15 -4
  48. data/lib/gooddata/mixins/md_object_query.rb +42 -20
  49. data/lib/gooddata/mixins/md_relations.rb +21 -12
  50. data/lib/gooddata/mixins/meta_getter.rb +2 -0
  51. data/lib/gooddata/mixins/meta_property_reader.rb +2 -0
  52. data/lib/gooddata/mixins/meta_property_writer.rb +2 -0
  53. data/lib/gooddata/mixins/rest_resource.rb +32 -10
  54. data/lib/gooddata/mixins/root_key_getter.rb +1 -1
  55. data/lib/gooddata/models/data_result.rb +3 -1
  56. data/lib/gooddata/models/domain.rb +31 -22
  57. data/lib/gooddata/models/empty_result.rb +22 -0
  58. data/lib/gooddata/models/invitation.rb +11 -9
  59. data/lib/gooddata/models/links.rb +5 -3
  60. data/lib/gooddata/models/membership.rb +23 -28
  61. data/lib/gooddata/models/metadata.rb +35 -35
  62. data/lib/gooddata/models/metadata/attribute.rb +10 -8
  63. data/lib/gooddata/models/metadata/dashboard.rb +1 -1
  64. data/lib/gooddata/models/metadata/fact.rb +3 -3
  65. data/lib/gooddata/models/metadata/label.rb +4 -4
  66. data/lib/gooddata/models/metadata/metric.rb +76 -38
  67. data/lib/gooddata/models/metadata/report.rb +52 -17
  68. data/lib/gooddata/models/metadata/report_definition.rb +178 -28
  69. data/lib/gooddata/models/model.rb +13 -6
  70. data/lib/gooddata/models/process.rb +93 -30
  71. data/lib/gooddata/models/profile.rb +18 -20
  72. data/lib/gooddata/models/project.rb +344 -127
  73. data/lib/gooddata/models/project_creator.rb +32 -22
  74. data/lib/gooddata/models/project_metadata.rb +26 -14
  75. data/lib/gooddata/models/project_role.rb +15 -17
  76. data/lib/gooddata/models/report_data_result.rb +4 -0
  77. data/lib/gooddata/models/schedule.rb +51 -20
  78. data/lib/gooddata/models/schema_blueprint.rb +9 -3
  79. data/lib/gooddata/rest/README.md +37 -0
  80. data/lib/gooddata/rest/client.rb +318 -0
  81. data/lib/gooddata/rest/connection.rb +235 -0
  82. data/lib/gooddata/rest/connections/connections.rb +8 -0
  83. data/lib/gooddata/rest/connections/dummy_connection.rb +52 -0
  84. data/lib/gooddata/rest/connections/rest_client_connection.rb +177 -0
  85. data/lib/gooddata/rest/object.rb +32 -0
  86. data/lib/gooddata/rest/object_factory.rb +67 -0
  87. data/lib/gooddata/rest/resource.rb +17 -0
  88. data/lib/gooddata/rest/rest.rb +20 -0
  89. data/lib/gooddata/version.rb +1 -1
  90. data/spec/data/cc/data/source/commits.csv +4 -0
  91. data/spec/data/cc/data/source/devs.csv +4 -0
  92. data/spec/data/cc/data/source/repos.csv +3 -0
  93. data/spec/data/cc/devel.prm +0 -0
  94. data/spec/data/cc/graph/graph.grf +11 -0
  95. data/spec/data/cc/workspace.prm +19 -0
  96. data/spec/data/hello_world_process/hello_world.rb +1 -0
  97. data/spec/data/hello_world_process/hello_world.zip +0 -0
  98. data/spec/data/users.csv +12 -12
  99. data/spec/helpers/connection_helper.rb +6 -0
  100. data/spec/helpers/process_helper.rb +12 -0
  101. data/spec/helpers/project_helper.rb +2 -2
  102. data/spec/integration/command_projects_spec.rb +11 -9
  103. data/spec/integration/create_from_template_spec.rb +6 -2
  104. data/spec/integration/full_process_schedule_spec.rb +49 -36
  105. data/spec/integration/full_project_spec.rb +221 -256
  106. data/spec/integration/partial_md_export_import_spec.rb +18 -17
  107. data/spec/logging_in_logging_out_spec.rb +17 -8
  108. data/spec/spec_helper.rb +4 -2
  109. data/spec/unit/cli/commands/cmd_api_spec.rb +1 -1
  110. data/spec/unit/cli/commands/cmd_auth_spec.rb +1 -1
  111. data/spec/unit/cli/commands/cmd_domain_spec.rb +29 -3
  112. data/spec/unit/cli/commands/cmd_process_spec.rb +1 -1
  113. data/spec/unit/cli/commands/cmd_project_spec.rb +1 -1
  114. data/spec/unit/cli/commands/cmd_role_spec.rb +13 -2
  115. data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +1 -1
  116. data/spec/unit/cli/commands/cmd_scaffold_spec.rb +1 -1
  117. data/spec/unit/cli/commands/cmd_user_spec.rb +1 -1
  118. data/spec/unit/commands/command_api_spec.rb +0 -19
  119. data/spec/unit/commands/command_auth_spec.rb +20 -13
  120. data/spec/unit/commands/command_dataset_spec.rb +2 -2
  121. data/spec/unit/commands/command_process_spec.rb +24 -21
  122. data/spec/unit/commands/command_projects_spec.rb +2 -2
  123. data/spec/unit/commands/command_scaffold_spec.rb +2 -2
  124. data/spec/unit/commands/command_user_spec.rb +3 -3
  125. data/spec/unit/core/connection_spec.rb +9 -10
  126. data/spec/unit/core/project_spec.rb +8 -4
  127. data/spec/unit/core/rest_spec.rb +6 -6
  128. data/spec/unit/models/domain_spec.rb +14 -7
  129. data/spec/unit/models/invitation_spec.rb +2 -2
  130. data/spec/unit/models/membership_spec.rb +5 -5
  131. data/spec/unit/models/metric_spec.rb +92 -0
  132. data/spec/unit/models/profile_spec.rb +25 -21
  133. data/spec/unit/models/project_blueprint_spec.rb +6 -6
  134. data/spec/unit/models/project_role_spec.rb +3 -5
  135. data/spec/unit/models/project_spec.rb +43 -37
  136. data/spec/unit/models/schedule_spec.rb +58 -107
  137. data/spec/unit/rest/resource_spec.rb +6 -0
  138. metadata +87 -10
  139. data/lib/gooddata/cli/commands/role_cmd.rb +0 -28
  140. data/lib/gooddata/core/connection.rb +0 -392
  141. data/lib/gooddata/core/threaded.rb +0 -14
  142. data/lib/gooddata/models/md_object.rb +0 -25
  143. data/lib/gooddata/models/metadata/folder.rb +0 -24
  144. data/spec/unit/models/md_object_spec.rb +0 -55
  145. data/spec/unit/models/metric.rb +0 -92
@@ -1,12 +1,12 @@
1
- First Name,Last Name,Email,Password,MUF,MUF ID,Role,Role ID,Project ID,Domain
2
- Gem,Tester,svarovsky+gem_tester@gooddata.com,jindrisska,Edit,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
3
- Test,User0,test.user.110@example.com,password0,Full,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
4
- Test,User1,test.user.111@example.com,password1,Full,,connectorsSystemRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
5
- Test,User2,test.user.112@example.com,password2,Full,,editorRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
6
- Test,User3,test.user.113@example.com,password3,Full,,dashboardOnlyRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
7
- Test,User4,test.user.114@example.com,password4,Full,,unverifiedAdminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
8
- Test,User5,test.user.115@example.com,password5,Full,,readOnlyUserRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
9
- Test,User6,test.user.116@example.com,password6,Full,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
10
- Test,User7,test.user.117@example.com,password7,Full,,connectorsSystemRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
11
- Test,User8,test.user.118@example.com,password8,Full,,editorRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
12
- Test,User9,test.user.119@example.com,password9,Full,,dashboardOnlyRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
1
+ First Name,Last Name,Email,Password,MUF,MUF ID,Role,Role ID,Project ID,Domain
2
+ Gem,Tester,svarovsky+gem_tester@gooddata.com,jindrisska,Edit,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
3
+ Test,User0,test.user.110@example.com,password0,Full,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
4
+ Test,User1,test.user.111@example.com,password1,Full,,connectorsSystemRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
5
+ Test,User2,test.user.112@example.com,password2,Full,,editorRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
6
+ Test,User3,test.user.113@example.com,password3,Full,,dashboardOnlyRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
7
+ Test,User4,test.user.114@example.com,password4,Full,,unverifiedAdminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
8
+ Test,User5,test.user.115@example.com,password5,Full,,readOnlyUserRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
9
+ Test,User6,test.user.116@example.com,password6,Full,,adminRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
10
+ Test,User7,test.user.117@example.com,password7,Full,,connectorsSystemRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
11
+ Test,User8,test.user.118@example.com,password8,Full,,editorRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
12
+ Test,User9,test.user.119@example.com,password9,Full,,dashboardOnlyRole,5,wgqhml3se0035s8n5byqdq0j0ob5jam4,gooddata-tomas-svarovsky
@@ -16,6 +16,12 @@ module ConnectionHelper
16
16
  GoodData::connect(username, password)
17
17
  end
18
18
 
19
+ def self.disconnect
20
+ conn = GoodData.connection.connection
21
+ GoodData.disconnect
22
+ puts conn.stats_table
23
+ end
24
+
19
25
  # Creates connection using environment varibles GD_GEM_USER and GD_GEM_PASSWORD
20
26
  def self.create_private_connection
21
27
  username = ENV['GD_GEM_USER'] || DEFAULT_USERNAME
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ # Global requires
4
+ require 'multi_json'
5
+
6
+ # Local requires
7
+ require 'gooddata/models/models'
8
+
9
+ module ProcessHelper
10
+ PROCESS_ID = 'dc143d80-58a1-4acd-96b6-8d11fc4571de'
11
+ DEPLOY_NAME = 'graph'
12
+ end
@@ -12,7 +12,7 @@ module ProjectHelper
12
12
  PROJECT_TITLE = 'GoodTravis'
13
13
  PROJECT_SUMMARY = 'No summary'
14
14
 
15
- def self.get_default_project
16
- GoodData::Project[PROJECT_ID]
15
+ def self.get_default_project(opts = { :client => GoodData.connection })
16
+ GoodData::Project[PROJECT_ID, opts]
17
17
  end
18
18
  end
@@ -3,25 +3,27 @@ require 'gooddata/commands/project'
3
3
 
4
4
  describe GoodData::Command::Project, :constraint => 'slow' do
5
5
  before(:all) do
6
+ @client = ConnectionHelper.create_default_connection
7
+
6
8
  @blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/test_project_model_spec.json")
7
9
  @module_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/additional_dataset_module.json")
8
10
 
9
- ConnectionHelper::create_default_connection
10
- @project = GoodData::Command::Project.build({:spec => @blueprint, :token => ConnectionHelper::GD_PROJECT_TOKEN})
11
+ @project = GoodData::Command::Project.build({:spec => @blueprint, :token => ConnectionHelper::GD_PROJECT_TOKEN, :client => @client})
11
12
  end
12
13
 
13
14
  after(:all) do
14
15
  @project.delete unless @project.nil?
16
+
17
+ @client.disconnect
15
18
  end
16
19
 
17
20
  it "should update the project" do
18
21
  @blueprint.merge!(@module_blueprint)
19
- GoodData.with_project(@project) do |p|
20
- p.blueprint.datasets.count.should == 3
21
- p.blueprint.datasets(:include_date_dimensions => true).count.should == 4
22
- GoodData::Command::Project.update({:spec => @blueprint, :project => p})
23
- p.blueprint.datasets.count.should == 4
24
- p.blueprint.datasets(:include_date_dimensions => true).count.should == 5
25
- end
22
+ @project.blueprint.datasets.count.should == 3
23
+ @project.blueprint.datasets(:include_date_dimensions => true).count.should == 4
24
+ GoodData::Command::Project.update({:spec => @blueprint, :client => @client, :project => @project})
25
+ @project.blueprint.datasets.count.should == 4
26
+ @project.blueprint.datasets(:include_date_dimensions => true).count.should == 5
27
+
26
28
  end
27
29
  end
@@ -2,11 +2,15 @@ require 'gooddata'
2
2
 
3
3
  describe "Spin a project from template", :constraint => 'slow' do
4
4
  before(:all) do
5
- ConnectionHelper::create_default_connection
5
+ @client = ConnectionHelper.create_default_connection
6
+ end
7
+
8
+ after(:all) do
9
+ @client.disconnect
6
10
  end
7
11
 
8
12
  it "should spin a project from a template that does not exist. It should throw an error" do
9
- expect{GoodData::Project.create(:title => "Test project", :template => "/some/nonexisting/template/uri", :auth_token => ConnectionHelper::GD_PROJECT_TOKEN)}.to raise_error
13
+ expect{GoodData::Project.create(:title => "Test project", :template => "/some/nonexisting/template/uri", :auth_token => ConnectionHelper::GD_PROJECT_TOKEN, :client => @client)}.to raise_error
10
14
  end
11
15
 
12
16
  end
@@ -2,68 +2,81 @@ require 'gooddata'
2
2
 
3
3
  describe "Full process and schedule exercise", :constraint => 'slow' do
4
4
  before(:all) do
5
- ConnectionHelper::create_default_connection
6
- @project = GoodData::Project.create(title: 'Project for schedule testing', auth_token: ConnectionHelper::GD_PROJECT_TOKEN)
7
- @process = GoodData::Process.with_deploy('./spec/data/ruby_process',
5
+ @client = ConnectionHelper::create_default_connection
6
+ @project = GoodData::Project.create(title: 'Project for schedule testing', auth_token: ConnectionHelper::GD_PROJECT_TOKEN, :client => @client)
7
+ @process = @project.deploy_process('./spec/data/ruby_process',
8
8
  type: 'RUBY',
9
- project: @project,
10
9
  name: 'Test ETL Process')
11
10
  end
12
11
 
13
12
  after(:all) do
14
13
  @process.delete if @process
15
14
  @project.delete if @project
15
+ @client.disconnect
16
16
  end
17
17
 
18
18
  it "should be able to execute a process" do
19
- pending('Account cannot execute Ruby')
20
- GoodData.with_project(@project) do |project|
21
- result = @process.execute(@process.executables.first)
22
- log = GoodData.get(result['executionDetail']['links']['log'])
23
- expect(log.index('Hello Ruby executors')).not_to eq nil
24
- expect(log.index('Hello Ruby from the deep')).not_to eq nil
25
- end
19
+ result = @process.execute(@process.executables.first)
20
+ log = @client.get(result['executionDetail']['links']['log'])
21
+ expect(log.index('Hello Ruby executors')).not_to eq nil
22
+ expect(log.index('Hello Ruby from the deep')).not_to eq nil
26
23
  end
27
24
 
28
25
  it "should be able to grab executables" do
29
- pending('Account cannot execute Ruby')
26
+
30
27
  expect(@process.executables).to eq ['./process.rb']
31
28
  end
32
29
 
33
30
  it "should have empty schedules on deploy" do
34
- pending('Account cannot execute Ruby')
35
- GoodData.with_project(@project) do |project|
36
- expect(@process.schedules).to eq []
37
- end
31
+ expect(@process.schedules).to eq []
38
32
  end
39
33
 
40
- it "should be able to schedule" do
41
- pending('Account cannot execute Ruby')
42
- GoodData.with_project(@project) do |project|
43
- schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
44
- expect(@process.schedules.count).to eq 1
45
- expect(@process.schedules).to eq [schedule]
46
- schedule.delete
47
- end
34
+ it "should be able to delete schedule" do
35
+ schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
36
+ expect(@process.schedules.count).to eq 1
37
+ expect(@process.schedules).to eq [schedule]
38
+ schedule.delete
48
39
  end
49
40
 
50
41
  it "should be possible to read status of schedule" do
51
- pending('Account cannot execute Ruby')
52
- GoodData.with_project(@project) do |project|
53
- schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
54
- expect(schedule.state).to eq 'ENABLED'
55
- schedule.delete
56
- end
42
+ schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
43
+ expect(schedule.state).to eq 'ENABLED'
44
+ schedule.delete
57
45
  end
58
46
 
59
47
  it "should be possible to execute schedule" do
60
- pending('Account cannot execute Ruby')
61
- GoodData.with_project(@project) do |project|
62
- schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
48
+ schedule = @process.create_schedule('0 15 27 7 *', @process.executables.first)
49
+ result = schedule.execute
50
+ log = @client.get(result['execution']['log'])
51
+ expect(log.index('Hello Ruby executors')).not_to eq nil
52
+ expect(log.index('Hello Ruby from the deep')).not_to eq nil
53
+ end
54
+
55
+ it "should be possible to deploy only a single file" do
56
+ process = @project.deploy_process('./spec/data/hello_world_process/hello_world.rb',
57
+ type: 'RUBY',
58
+ name: 'Test ETL one file Process')
59
+ begin
60
+ schedule = process.create_schedule('0 15 27 7 *', process.executables.first)
61
+ result = schedule.execute
62
+ log = @client.get(result['execution']['log'])
63
+ expect(log.index('HELLO WORLD')).not_to eq nil
64
+ ensure
65
+ process && process.delete
66
+ end
67
+ end
68
+
69
+ it "should be possible to deploy already zipped file" do
70
+ process = @project.deploy_process('./spec/data/hello_world_process/hello_world.zip',
71
+ type: 'RUBY',
72
+ name: 'Test ETL zipped file Process')
73
+ begin
74
+ schedule = process.create_schedule('0 15 27 7 *', process.executables.first)
63
75
  result = schedule.execute
64
- log = GoodData.get(result['execution']['log'])
65
- expect(log.index('Hello Ruby executors')).not_to eq nil
66
- expect(log.index('Hello Ruby from the deep')).not_to eq nil
76
+ log = @client.get(result['execution']['log'])
77
+ expect(log.index('HELLO WORLD')).not_to eq nil
78
+ ensure
79
+ process && process.delete
67
80
  end
68
81
  end
69
82
  end
@@ -2,55 +2,57 @@ require 'gooddata'
2
2
 
3
3
  describe "Full project implementation", :constraint => 'slow' do
4
4
  before(:all) do
5
- @spec = JSON.parse(File.read('./spec/data/test_project_model_spec.json'), :symbolize_names => true)
6
- @invalid_spec = JSON.parse(File.read('./spec/data/blueprint_invalid.json'), :symbolize_names => true)
7
- ConnectionHelper::create_default_connection
8
- @project = GoodData::Model::ProjectCreator.migrate(:spec => @spec, :token => ConnectionHelper::GD_PROJECT_TOKEN)
5
+ @spec = JSON.parse(File.read("./spec/data/test_project_model_spec.json"), :symbolize_names => true)
6
+ @invalid_spec = JSON.parse(File.read("./spec/data/blueprint_invalid.json"), :symbolize_names => true)
7
+ @client = ConnectionHelper::create_default_connection
8
+ @project = GoodData::Model::ProjectCreator.migrate({:spec => @spec, :token => ConnectionHelper::GD_PROJECT_TOKEN, :client => @client})
9
9
  end
10
10
 
11
11
  after(:all) do
12
12
  @project.delete unless @project.nil?
13
+
14
+ @client.disconnect
13
15
  end
14
16
 
15
17
  it "should not build an invalid model" do
16
18
  expect {
17
- GoodData::Model::ProjectCreator.migrate({:spec => @invalid_spec, :token => ConnectionHelper::GD_PROJECT_TOKEN})
19
+ GoodData::Model::ProjectCreator.migrate({:spec => @invalid_spec, :token => ConnectionHelper::GD_PROJECT_TOKEN, :client => @client})
18
20
  }.to raise_error(GoodData::ValidationError)
19
21
  end
20
22
 
21
23
  it "should contain datasets" do
22
- GoodData.with_project(@project) do |p|
23
- p.blueprint.tap do |bp|
24
- expect(bp.datasets.count).to eq 3
25
- expect(bp.datasets(:include_date_dimensions => true).count).to eq 4
26
- end
24
+ @project.blueprint.tap do |bp|
25
+ expect(bp.datasets.count).to eq 3
26
+ expect(bp.datasets(:include_date_dimensions => true).count).to eq 4
27
27
  end
28
28
  end
29
29
 
30
30
  it "should be able to rename a project" do
31
- GoodData.with_project(@project) do |p|
32
- former_title = p.title
33
- a_title = (0...8).map { (65 + rand(26)).chr }.join
34
- p.title = a_title
35
- p.save
36
- expect(p.title).to eq a_title
37
- p.title = former_title
38
- p.save
39
- end
31
+ former_title = @project.title
32
+ a_title = (0...8).map { (65 + rand(26)).chr }.join
33
+ @project.title = a_title
34
+ @project.save
35
+ expect(@project.title).to eq a_title
36
+ @project.title = former_title
37
+ @project.save
40
38
  end
41
39
 
42
40
  it "should be able to validate a project" do
43
- GoodData.with_project(@project) do |p|
44
- p.validate
45
- end
41
+ @project.validate
46
42
  end
47
43
 
48
44
  it "should compute an empty metric" do
49
- GoodData.with_project(@project) do |p|
50
- f = GoodData::Fact.find_first_by_title('Lines Changed')
51
- metric = GoodData::Metric.xcreate("SELECT SUM(#\"#{f.title}\")")
52
- metric.execute.should be_nil
53
- end
45
+ f = @project.fact_by_title('Lines Changed')
46
+ metric = @project.create_metric("SELECT SUM(#\"#{f.title}\")")
47
+ expect(metric.execute).to be_nil
48
+ end
49
+
50
+ it "should compute an empty report def" do
51
+ @project.delete_all_data(force: true)
52
+ f = @project.fact_by_title('Lines Changed')
53
+ metric = @project.create_metric("SELECT SUM(#\"#{f.title}\")")
54
+ res = GoodData::ReportDefinition.execute(:left => [metric], :client => @client, :project => @project);
55
+ expect(res).to be_empty
54
56
  end
55
57
 
56
58
  it "should load the data" do
@@ -61,7 +63,7 @@ describe "Full project implementation", :constraint => 'slow' do
61
63
  [1,"01/01/2014",1,1],
62
64
  [3,"01/02/2014",2,2],
63
65
  [5,"05/02/2014",3,1]]
64
- GoodData::Model.upload_data(commits_data, blueprint, 'commits')
66
+ GoodData::Model.upload_data(commits_data, blueprint, 'commits', :client => @client, :project => @project)
65
67
  # blueprint.find_dataset('commits').upload(commits_data)
66
68
 
67
69
  devs_data = [
@@ -69,329 +71,292 @@ describe "Full project implementation", :constraint => 'slow' do
69
71
  [1, "tomas@gooddata.com"],
70
72
  [2, "petr@gooddata.com"],
71
73
  [3, "jirka@gooddata.com"]]
72
- GoodData::Model.upload_data(devs_data, blueprint, 'devs')
74
+ GoodData::Model.upload_data(devs_data, blueprint, 'devs', :client => @client, :project => @project)
73
75
  # blueprint.find_dataset('devs').upload(devs_data)
74
76
  end
75
77
  end
76
78
 
77
79
  it "should compute a metric" do
78
- GoodData.with_project(@project) do |p|
79
- f = GoodData::Fact.find_first_by_title('Lines Changed')
80
- metric = GoodData::Metric.xcreate("SELECT SUM(#\"#{f.title}\")")
81
- metric.execute.should == 9
82
- end
80
+ f = @project.fact_by_title('Lines Changed')
81
+ metric = @project.create_metric("SELECT SUM(#\"#{f.title}\")")
82
+ expect(metric.execute).to eq 9
83
83
  end
84
84
 
85
85
  it "should execute an anonymous metric twice and not fail" do
86
- GoodData.with_project(@project) do |p|
87
- f = GoodData::Fact.find_first_by_title('Lines Changed')
88
- metric = GoodData::Metric.xcreate("SELECT SUM(#\"#{f.title}\")")
89
- metric.execute.should == 9
90
- # Since GD platform cannot execute inline specified metric the metric has to be saved
91
- # The code tries to resolve this as transparently as possible
92
- metric.execute.should == 9
93
- end
86
+ f = @project.fact_by_title('Lines Changed')
87
+ metric = @project.create_metric("SELECT SUM(#\"#{f.title}\")")
88
+ expect(metric.execute).to eq 9
89
+ # Since GD platform cannot execute inline specified metric the metric has to be saved
90
+ # The code tries to resolve this as transparently as possible
91
+ # Here we are testing that you can execute the metric twice. The first execution is on unsaved metric
92
+ # We wanna make sure that when we are cleaning up we are not messing things up
93
+ expect(metric.execute).to eq 9
94
94
  end
95
95
 
96
- it "should compute a report" do
97
- GoodData.with_project(@project) do |p|
98
- f = GoodData::Fact.find_first_by_title('Lines Changed')
99
- # TODO: Here we create metric which is not deleted and is used by another test - "should exercise the object relations and getting them in various ways"
100
- metric = GoodData::Metric.xcreate(:title => "My metric", :expression => "SELECT SUM(#\"#{f.title}\")")
101
- metric.save
102
- result = GoodData::ReportDefinition.execute(:title => "My report", :top => [metric], :left => ['label.devs.dev_id.email'])
103
- result[1][1].should == 3
104
- result.include_row?(["jirka@gooddata.com", 5]).should == true
105
-
106
- result2 = GoodData::ReportDefinition.create(:title => "My report", :top => [metric], :left => ['label.devs.dev_id.email']).execute
107
- result2[1][1].should == 3
108
- result2.include_row?(["jirka@gooddata.com", 5]).should == true
109
- result2.should == result
110
- end
96
+ it "should compute a report def" do
97
+ f = @project.fact_by_title('Lines Changed')
98
+
99
+ # TODO: Here we create metric which is not deleted and is used by another test - "should exercise the object relations and getting them in various ways"
100
+ metric = @project.create_metric("SELECT SUM(#\"#{f.title}\")", :title => "My metric")
101
+ metric.save
102
+ result = GoodData::ReportDefinition.execute(:title => "My report", :top => [metric], :left => ['label.devs.dev_id.email'], :client => @client, :project => @project)
103
+ expect(result[1][1]).to eq 3
104
+ expect(result.include_row?(["jirka@gooddata.com", 5])).to be true
105
+
106
+ result2 = GoodData::ReportDefinition.create(:title => "My report", :top => [metric], :left => ['label.devs.dev_id.email'], :client => @client, :project => @project).execute
107
+ expect(result2[1][1]).to eq 3
108
+ expect(result2.include_row?(["jirka@gooddata.com", 5])).to eq true
109
+ expect(result2).to eq result
111
110
  end
112
111
 
113
- it "should throw an exception if trying to access object without explicitely specifying a project" do
114
- expect do
115
- GoodData::Metric[:all]
116
- end.to raise_exception(GoodData::NoProjectError)
112
+ it "should be able to purge report from older revisions" do
113
+ m = @project.metrics.first
114
+ r = @project.create_report(top: [m], title: 'xy')
115
+ expect(r.definitions.count).to eq 1
116
+
117
+ rd = GoodData::ReportDefinition.create(:top => [m], :client => @client, :project => @project)
118
+ rd.save
119
+ r.add_definition(rd)
120
+ r.save
121
+ expect(r.definitions.count).to eq 2
117
122
  end
118
123
 
119
124
  it "should be possible to get all metrics" do
120
- GoodData.with_project(@project) do |p|
121
- metrics1 = GoodData::Metric[:all]
122
- metrics2 = GoodData::Metric.all
123
- metrics1.should == metrics2
124
- end
125
+ metrics1 = @project.metrics
126
+ expect(metrics1.count).to be >= 0
125
127
  end
126
128
 
127
129
  it "should be possible to get all metrics with full objects" do
128
- GoodData.with_project(@project) do |p|
129
- metrics1 = GoodData::Metric[:all, :full => true]
130
- metrics2 = GoodData::Metric.all :full => true
131
- metrics1.should == metrics2
132
- end
130
+ metrics1 = @project.metrics(:all, full: false)
131
+ expect(metrics1.first.class).to be Hash
133
132
  end
134
133
 
135
134
  it "should be able to get a metric by identifier" do
136
- GoodData.with_project(@project) do |p|
137
- metrics = GoodData::Metric.all :full => true
138
- metric = GoodData::Metric[metrics.first.identifier]
139
- metric.identifier == metrics.first.identifier
140
- metrics.first == metric
141
- end
135
+ metrics = @project.metrics
136
+ metric = @project.metrics(metrics.first.identifier)
137
+ expect(metric.identifier).to eq metrics.first.identifier
138
+ expect(metrics.first).to eq metric
142
139
  end
143
140
 
144
141
  it "should be able to get a metric by uri" do
145
- GoodData.with_project(@project) do |p|
146
- metrics = GoodData::Metric.all :full => true
147
- metric = GoodData::Metric[metrics.first.uri]
148
- metric.uri == metrics.first.uri
149
- metrics.first == metric
150
- end
142
+ metrics = @project.metrics
143
+ metric = @project.metrics(metrics.first.uri)
144
+ expect(metric.uri).to eq metrics.first.uri
145
+ expect(metrics.first).to eq metric
151
146
  end
152
147
 
153
148
  it "should be able to get a metric by object id" do
154
- GoodData.with_project(@project) do |p|
155
- metrics = GoodData::Metric.all :full => true
156
- metric = GoodData::Metric[metrics.first.obj_id]
157
- metric.obj_id == metrics.first.obj_id
158
- metrics.first == metric
159
- end
149
+ metrics = @project.metrics
150
+ metric = @project.metrics(metrics.first.obj_id)
151
+ expect(metric.obj_id).to eq metrics.first.obj_id
152
+ expect(metrics.first).to eq metric
160
153
  end
161
154
 
162
155
  it "should exercise the object relations and getting them in various ways" do
163
- GoodData.with_project(@project) do |p|
156
+ # Find a metric by name
157
+ metric = @project.metric_by_title('My metric')
158
+ the_same_metric = @project.metrics(metric)
159
+ expect(metric).to eq the_same_metric
164
160
 
165
- # Find a metric by name
166
- metric = GoodData::Metric.find_first_by_title('My metric')
167
- the_same_metric = GoodData::Metric[metric]
168
- metric.should == metric
161
+ # grab fact in several different ways
162
+ fact1 = @project.fact_by_title('Lines Changed')
163
+ fact2 = @project.facts(fact1.identifier)
164
+ fact3 = @project.facts(fact2.obj_id)
165
+ fact4 = @project.facts(fact3.uri)
166
+ fact5 = @client.create(GoodData::Fact, fact4)
169
167
 
170
- # grab fact in several different ways
171
- fact1 = GoodData::Fact.find_first_by_title('Lines Changed')
172
- fact2 = GoodData::Fact[fact1.identifier]
173
- fact3 = GoodData::Fact[fact2.obj_id]
174
- fact4 = GoodData::Fact[fact3.uri]
175
- fact5 = GoodData::Fact.new(fact4)
168
+ # All should be the same
169
+ expect(fact1).to eq fact2
170
+ expect(fact1).to eq fact2
171
+ expect(fact1).to eq fact3
172
+ expect(fact1).to eq fact4
173
+ expect(fact1).to eq fact5
176
174
 
177
- # All should be the same
178
- fact1.should == fact2
179
- fact1.should == fact2
180
- fact1.should == fact3
181
- fact1.should == fact4
182
- fact1.should == fact5
175
+ fact3.title = "Somewhat changed title"
176
+ expect(fact1).not_to eq fact3
183
177
 
184
- fact3.title = "Somewhat changed title"
185
- fact1.should_not == fact3
178
+ metric.using(nil)
179
+ expect(metric.using('fact', :client => @client, :project => @project).count).to eq 1
186
180
 
187
- metric.using
188
- metric.using('fact').count.should == 1
181
+ fact1.used_by(nil)
182
+ expect(fact1.used_by('metric', :client => @client, :project => @project).count).to eq 1
189
183
 
190
- fact1.used_by
191
- fact1.used_by('metric').count.should == 1
184
+ res = metric.using?(fact1)
185
+ expect(res).to be(true)
192
186
 
193
- res = metric.using?(fact1)
194
- expect(res).to be(true)
187
+ res = fact1.using?(metric)
188
+ expect(res).to be(false)
195
189
 
196
- res = fact1.using?(metric)
197
- expect(res).to be(false)
190
+ res = metric.used_by?(fact1)
191
+ expect(res).to be(false)
198
192
 
199
- res = metric.used_by?(fact1)
200
- expect(res).to be(false)
201
-
202
- res = fact1.used_by?(metric)
203
- expect(res).to be(true)
204
- end
193
+ res = fact1.used_by?(metric)
194
+ expect(res).to be(true)
205
195
  end
206
196
 
207
197
  it "should try setting and getting by tags" do
208
- GoodData.with_project(@project) do |p|
209
- fact = GoodData::Fact.find_first_by_title('Lines Changed')
210
- fact.tags.should be_empty
198
+ fact = @project.fact_by_title('Lines Changed')
199
+ expect(fact.tags.empty?).to be_true
211
200
 
212
- fact.tags = "tag1,tag2,tag3"
213
- fact.save
201
+ fact.tags = "tag1,tag2,tag3"
202
+ fact.save
214
203
 
215
- tagged_facts = GoodData::Fact.find_by_tag('tag3')
216
- tagged_facts.count.should == 1
217
- end
204
+ tagged_facts = GoodData::Fact.find_by_tag('tag3', :client => @client, :project => @project)
205
+ expect(tagged_facts.count).to eq 1
218
206
  end
219
207
 
220
208
  it "should contain metadata for each dataset in project metadata" do
221
- GoodData.with_project(@project) do |p|
222
- k = GoodData::ProjectMetadata.keys
223
- k.should include("manifest_devs")
224
- end
209
+ k = GoodData::ProjectMetadata.keys(:client => @client, :project => @project)
210
+ expect(k).to include("manifest_devs")
225
211
  end
226
212
 
227
213
  it "should be able to interpolate metric based on" do
228
- GoodData.with_project(@project) do |p|
229
- res = GoodData::Metric.xexecute "SELECT SUM(![fact.commits.lines_changed])"
230
- res.should == 9
214
+ res = GoodData::Metric.xexecute "SELECT SUM(![fact.commits.lines_changed])", :client => @client, :project => @project
215
+ expect(res).to eq 9
231
216
 
232
- res = GoodData::Metric.xexecute({:expression => "SELECT SUM(![fact.commits.lines_changed])"})
233
- res.should == 9
217
+ res = GoodData::Metric.xexecute( "SELECT SUM(![fact.commits.lines_changed])", :client => @client, :project => @project)
218
+ expect(res).to eq 9
234
219
 
235
- res = GoodData::Metric.execute({:expression => "SELECT SUM(![fact.commits.lines_changed])", :extended_notation => true})
236
- res.should == 9
220
+ res = GoodData::Metric.execute("SELECT SUM(![fact.commits.lines_changed])", :extended_notation => true, :client => @client, :project => @project)
221
+ expect(res).to eq 9
237
222
 
238
- res = GoodData::Metric.execute("SELECT SUM(![fact.commits.lines_changed])", :extended_notation => true)
239
- res.should == 9
223
+ res = GoodData::Metric.execute("SELECT SUM(![fact.commits.lines_changed])", :extended_notation => true, :client => @client, :project => @project)
224
+ expect(res).to eq 9
240
225
 
241
- fact = GoodData::Fact.find_first_by_title('Lines Changed')
242
- fact.fact?.should == true
243
- res = fact.create_metric(:type => :sum).execute
244
- res.should == 9
245
- end
226
+ fact = @project.fact_by_title('Lines Changed')
227
+ expect(fact.fact?).to be true
228
+ res = fact.create_metric(:type => :sum).execute
229
+ expect(res).to eq 9
246
230
  end
247
231
 
248
232
  it "should load the data" do
249
- GoodData.with_project(@project) do |p|
250
- blueprint = GoodData::Model::ProjectBlueprint.new(@spec)
251
- devs_data = [
252
- ["dev_id", "email"],
253
- [4, "josh@gooddata.com"]]
254
- GoodData::Model.upload_data(devs_data, blueprint, 'devs', mode: 'INCREMENTAL' )
255
- # blueprint.find_dataset('devs').upload(devs_data, :load => 'INCREMENTAL')
256
- end
233
+ blueprint = GoodData::Model::ProjectBlueprint.new(@spec)
234
+ devs_data = [
235
+ ["dev_id", "email"],
236
+ [4, "josh@gooddata.com"]]
237
+ GoodData::Model.upload_data(devs_data, blueprint, 'devs', mode: 'INCREMENTAL', :client => @client, :project => @project)
238
+ # blueprint.find_dataset('devs').upload(devs_data, :load => 'INCREMENTAL')
257
239
  end
258
240
 
259
241
  it "should have more users" do
260
- GoodData.with_project(@project) do |p|
261
- attribute = GoodData::Attribute['attr.devs.dev_id']
262
- attribute.attribute?.should == true
263
- attribute.create_metric.execute.should == 4
264
- end
242
+ attribute = @project.attributes('attr.devs.dev_id')
243
+ expect(attribute.attribute?).to be true
244
+ expect(attribute.create_metric.execute).to eq 4
265
245
  end
266
246
 
267
247
  it "should tell you whether metric contains a certain attribute" do
268
- GoodData.with_project(@project) do |p|
269
- attribute = GoodData::Attribute['attr.devs.dev_id']
270
- repo_attribute = GoodData::Attribute['attr.repos.repo_id']
271
- metric = attribute.create_metric(:title => "My test metric")
272
- metric.save
273
- metric.execute.should == 4
274
-
275
- metric.contain?(attribute).should == true
276
- metric.contain?(repo_attribute).should == false
277
-
278
- metric.replace(attribute, repo_attribute)
279
- metric.save
280
- metric.execute.should_not == 4
281
-
282
- l = attribute.primary_label
283
- value = l.values.first[:value]
284
- l.find_element_value(l.find_value_uri(value)).should == value
285
- expect(l.value?(value)).to eq true
286
- expect(l.value?("DEFINITELY NON EXISTENT VALUE HOPEFULLY")).to eq false
287
- end
248
+ attribute = @project.attributes('attr.devs.dev_id')
249
+ repo_attribute = @project.attributes('attr.repos.repo_id')
250
+ metric = attribute.create_metric(:title => "My test metric")
251
+ metric.save
252
+ expect(metric.execute).to eq 4
253
+
254
+ expect(metric.contain?(attribute)).to be true
255
+ expect(metric.contain?(repo_attribute)).to be false
256
+
257
+ metric.replace(attribute, repo_attribute)
258
+ metric.save
259
+ expect(metric.execute).not_to eq 4
260
+
261
+ l = attribute.primary_label
262
+ value = l.values.first[:value]
263
+ expect(l.find_element_value(l.find_value_uri(value))).to eq value
264
+ expect(l.value?(value)).to eq true
265
+ expect(l.value?("DEFINITELY NON EXISTENT VALUE HOPEFULLY")).to eq false
288
266
  end
289
267
 
290
268
  it "should be able to compute count of different datasets" do
291
- GoodData.with_project(@project) do |p|
292
- attribute = GoodData::Attribute['attr.devs.dev_id']
293
- dataset_attribute = GoodData::Attribute['attr.commits.factsof']
294
- attribute.create_metric(:attribute => dataset_attribute).execute.should == 3
295
- end
269
+ attribute = @project.attributes('attr.devs.dev_id')
270
+ dataset_attribute = @project.attributes('attr.commits.factsof')
271
+ expect(attribute.create_metric(:attribute => dataset_attribute).execute).to eq 3
296
272
  end
297
273
 
298
274
  it "should be able to tell you if a value is contained in a metric" do
299
- GoodData.with_project(@project) do |p|
300
- attribute = GoodData::Attribute['attr.devs.dev_id']
301
- label = attribute.primary_label
302
- value = label.values.first
303
- fact = GoodData::Fact['fact.commits.lines_changed']
304
- metric = GoodData::Metric.xcreate("SELECT SUM([#{fact.uri}]) WHERE [#{attribute.uri}] = [#{value[:uri]}]")
305
- metric.contain_value?(label, value[:value]).should == true
306
- end
275
+ attribute = @project.attributes('attr.devs.dev_id')
276
+ label = attribute.primary_label
277
+ value = label.values.first
278
+ fact = @project.facts('fact.commits.lines_changed')
279
+ metric = @project.create_metric("SELECT SUM([#{fact.uri}]) WHERE [#{attribute.uri}] = [#{value[:uri]}]")
280
+ expect(metric.contain_value?(label, value[:value])).to be true
307
281
  end
308
282
 
309
283
  it "should be able to replace the values in a metric" do
310
- GoodData.with_project(@project) do |p|
311
- attribute = GoodData::Attribute['attr.devs.dev_id']
312
- label = attribute.primary_label
313
- value = label.values.first
314
- different_value = label.values[1]
315
- fact = GoodData::Fact['fact.commits.lines_changed']
316
- metric = GoodData::Metric.xcreate("SELECT SUM([#{fact.uri}]) WHERE [#{attribute.uri}] = [#{value[:uri]}]")
317
- metric.replace_value(label, value[:value], different_value[:value])
318
- metric.contain_value?(label, value[:value]).should == false
319
- metric.pretty_expression.should == "SELECT SUM([Lines Changed]) WHERE [Dev] = [josh@gooddata.com]"
320
- end
284
+ attribute = @project.attributes('attr.devs.dev_id')
285
+ label = attribute.primary_label
286
+ value = label.values.first
287
+ different_value = label.values[1]
288
+ fact = @project.facts('fact.commits.lines_changed')
289
+ metric = @project.create_metric("SELECT SUM([#{fact.uri}]) WHERE [#{attribute.uri}] = [#{value[:uri]}]")
290
+ metric.replace_value(label, value[:value], different_value[:value])
291
+ expect(metric.contain_value?(label, value[:value])).to be false
292
+ expect(metric.pretty_expression).to eq "SELECT SUM([Lines Changed]) WHERE [Dev] = [josh@gooddata.com]"
321
293
  end
322
294
 
323
295
  it "should be able to lookup the attributes by regexp and return a collection" do
324
- GoodData.with_project(@project) do |p|
325
- attrs = GoodData::Attribute.find_by_title(/Date/i)
326
- attrs.count.should == 1
327
- end
296
+ attrs = @project.attributes_by_title(/Date/i)
297
+ expect(attrs.count).to eq 1
328
298
  end
329
299
 
330
300
  it "should be able to give you values of the label as an array of hashes" do
331
- GoodData.with_project(@project) do |p|
332
- attribute = GoodData::Attribute['attr.devs.dev_id']
333
- label = attribute.primary_label
334
- label.values.map {|v| v[:value]}.should == [
335
- 'jirka@gooddata.com',
336
- 'josh@gooddata.com',
337
- 'petr@gooddata.com',
338
- 'tomas@gooddata.com'
339
- ]
340
- end
301
+ attribute = @project.attributes('attr.devs.dev_id')
302
+ label = attribute.primary_label
303
+ expect(label.values.map { |v| v[:value] }).to eq [
304
+ 'jirka@gooddata.com',
305
+ 'josh@gooddata.com',
306
+ 'petr@gooddata.com',
307
+ 'tomas@gooddata.com'
308
+ ]
341
309
  end
342
310
 
343
311
  it "should be able to give you values for" do
344
- GoodData.with_project(@project) do |p|
345
- attribute = GoodData::Attribute['attr.devs.dev_id']
346
- attribute.values_for(2).should == ["tomas@gooddata.com", "1"]
347
- end
312
+ attribute = @project.attributes('attr.devs.dev_id')
313
+ expect(attribute.values_for(2)).to eq ["tomas@gooddata.com", "1"]
348
314
  end
349
315
 
350
316
  it "should be able to find specific element and give you the primary label value" do
351
- GoodData.with_project(@project) do |p|
352
- attribute = GoodData::Attribute['attr.devs.dev_id']
353
- GoodData::Attribute.find_element_value("#{attribute.uri}/elements?id=2").should == 'tomas@gooddata.com'
354
- end
317
+ attribute = @project.attributes('attr.devs.dev_id')
318
+ expect(@project.find_attribute_element_value("#{attribute.uri}/elements?id=2")).to eq 'tomas@gooddata.com'
355
319
  end
356
320
 
357
321
  it "should be able to give you label by name" do
358
- GoodData.with_project(@project) do |p|
359
- attribute = GoodData::Attribute['attr.devs.dev_id']
360
- label = attribute.label_by_name('email')
361
- label.label?.should == true
362
- label.title.should == 'Email'
363
- label.identifier.should == "label.devs.dev_id.email"
364
- label.attribute_uri.should == attribute.uri
365
- label.attribute.should == attribute
366
- end
322
+ attribute = @project.attributes('attr.devs.dev_id')
323
+ label = attribute.label_by_name('email')
324
+ expect(label.label?).to eq true
325
+ expect(label.title).to eq 'Email'
326
+ expect(label.identifier).to eq 'label.devs.dev_id.email'
327
+ expect(label.attribute_uri).to eq attribute.uri
328
+ expect(label.attribute).to eq attribute
367
329
  end
368
330
 
369
331
  it "should be able to return values of the attribute for inspection" do
370
- GoodData.with_project(@project) do |p|
371
- attribute = GoodData::Attribute['attr.devs.dev_id']
372
- vals = attribute.values
373
- vals.count.should == 4
374
- vals.first.count.should == 2
375
- vals.first.first[:value].should == "jirka@gooddata.com"
376
- end
332
+ attribute = @project.attributes('attr.devs.dev_id')
333
+ vals = attribute.values
334
+ expect(vals.count).to eq 4
335
+ expect(vals.first.count).to eq 2
336
+ expect(vals.first.first[:value]).to eq "jirka@gooddata.com"
377
337
  end
378
338
 
379
339
  it "should be able to save_as a metric" do
380
- GoodData.with_project(@project) do |p|
381
- m = GoodData::Metric.find_first_by_title("My test metric")
382
- cloned = m.save_as
383
- m_cloned = GoodData::Metric.find_first_by_title("Clone of My test metric")
384
- m_cloned.should == cloned
385
- m_cloned.execute.should == cloned.execute
386
- end
340
+ m = @project.metric_by_title("My test metric")
341
+ cloned = m.save_as
342
+ m_cloned = @project.metric_by_title("Clone of My test metric")
343
+ expect(m_cloned).to eq cloned
344
+ expect(m_cloned.execute).to eq cloned.execute
387
345
  end
388
346
 
389
347
  it "should be able to clone a project" do
390
- GoodData.with_project(@project) do |p|
391
- title = 'My new clone proejct'
392
- cloned_project = p.clone(title: title, auth_token: ConnectionHelper::GD_PROJECT_TOKEN)
393
- expect(cloned_project.title).to eq title
394
- cloned_project.delete
395
- end
348
+ title = 'My new clone proejct'
349
+ cloned_project = @project.clone(title: title, auth_token: ConnectionHelper::GD_PROJECT_TOKEN)
350
+ expect(cloned_project.title).to eq title
351
+ expect(cloned_project.facts.first.create_metric.execute).to eq 9
352
+ cloned_project.delete
353
+ end
354
+
355
+ it "should be able to clone a project without data" do
356
+ title = 'My new clone project'
357
+ cloned_project = @project.clone(title: title, auth_token: ConnectionHelper::GD_PROJECT_TOKEN, data: false)
358
+ expect(cloned_project.title).to eq title
359
+ expect(cloned_project.facts.first.create_metric.execute).to eq nil
360
+ cloned_project.delete
396
361
  end
397
362
  end