transifex-interface-ruby 0.0.1 → 0.0.2

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 (118) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +17 -17
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +22 -22
  6. data/README.md +517 -513
  7. data/Rakefile +1 -1
  8. data/lib/transifex.rb +84 -87
  9. data/lib/transifex/crud_requests.rb +43 -33
  10. data/lib/transifex/errors.rb +4 -4
  11. data/lib/transifex/project_components/language.rb +1 -1
  12. data/lib/transifex/project_components/language_components/coordinators.rb +4 -6
  13. data/lib/transifex/project_components/language_components/reviewers.rb +5 -8
  14. data/lib/transifex/project_components/language_components/translators.rb +6 -9
  15. data/lib/transifex/project_components/languages.rb +1 -1
  16. data/lib/transifex/resource.rb +1 -1
  17. data/lib/transifex/resource_components/content.rb +1 -1
  18. data/lib/transifex/resource_components/source.rb +1 -1
  19. data/lib/transifex/resource_components/stats.rb +1 -1
  20. data/lib/transifex/resource_components/translation.rb +1 -1
  21. data/lib/transifex/resource_components/translation_components/string.rb +1 -1
  22. data/lib/transifex/resource_components/translation_components/strings.rb +1 -1
  23. data/lib/transifex/resources.rb +1 -1
  24. data/lib/transifex/version.rb +3 -3
  25. data/spec/cassettes/fetch_formats.yml +121 -0
  26. data/spec/cassettes/language/fetch_language_info.yml +58 -0
  27. data/spec/cassettes/language/fetch_languages_info.yml +58 -0
  28. data/spec/cassettes/project/components/create_language.yml +95 -0
  29. data/spec/cassettes/project/components/create_language_non_existing_coordinator.yml +48 -0
  30. data/spec/cassettes/project/components/create_language_without_coordinator.yml +48 -0
  31. data/spec/cassettes/project/components/fetch_languages.yml +53 -0
  32. data/spec/cassettes/project/delete_project.yml +108 -0
  33. data/spec/cassettes/project/fetch_private_project_info.yml +59 -0
  34. data/spec/cassettes/project/fetch_with_details_private_project_info.yml +66 -0
  35. data/spec/cassettes/project/language/delete_language.yml +140 -0
  36. data/spec/cassettes/project/language/fetch_coordinators.yml +56 -0
  37. data/spec/cassettes/project/language/fetch_language_info.yml +52 -0
  38. data/spec/cassettes/project/language/fetch_reviewers.yml +56 -0
  39. data/spec/cassettes/project/language/fetch_translators.yml +54 -0
  40. data/spec/cassettes/project/language/fetch_with_details_language_info.yml +54 -0
  41. data/spec/cassettes/project/language/update_coordinators.yml +104 -0
  42. data/spec/cassettes/project/language/update_language.yml +100 -0
  43. data/spec/cassettes/project/language/update_non_existing_coordinator.yml +48 -0
  44. data/spec/cassettes/project/language/update_non_existing_language.yml +49 -0
  45. data/spec/cassettes/project/language/update_non_existing_reviewer.yml +101 -0
  46. data/spec/cassettes/project/language/update_non_existing_translator.yml +101 -0
  47. data/spec/cassettes/project/language/update_reviewers.yml +157 -0
  48. data/spec/cassettes/project/language/update_translators.yml +157 -0
  49. data/spec/cassettes/project/update_non_existing_attribute_private_project.yml +54 -0
  50. data/spec/cassettes/project/update_private_project.yml +120 -0
  51. data/spec/cassettes/project/update_with_missing_params_private_project.yml +54 -0
  52. data/spec/cassettes/projects/create_private_project.yml +111 -0
  53. data/spec/cassettes/projects/create_public_project.yml +111 -0
  54. data/spec/cassettes/projects/create_used_slug_project.yml +55 -0
  55. data/spec/cassettes/projects/fetch_projects.yml +61 -0
  56. data/spec/cassettes/resource/delete_not_existing_resource.yml +55 -0
  57. data/spec/cassettes/resource/delete_resource.yml +160 -0
  58. data/spec/cassettes/resource/fetch_all_languages_stats.yml +66 -0
  59. data/spec/cassettes/resource/fetch_content_as_file.yml +56 -0
  60. data/spec/cassettes/resource/fetch_content_as_hash.yml +58 -0
  61. data/spec/cassettes/resource/fetch_language_stats.yml +61 -0
  62. data/spec/cassettes/resource/fetch_not_existing_resource.yml +55 -0
  63. data/spec/cassettes/resource/fetch_resource_info.yml +59 -0
  64. data/spec/cassettes/resource/fetch_source_string_metadata.yml +52 -0
  65. data/spec/cassettes/resource/fetch_translations.yml +57 -0
  66. data/spec/cassettes/resource/fetch_updated_resource_info.yml +60 -0
  67. data/spec/cassettes/resource/fetch_updated_source_string_metadata.yml +52 -0
  68. data/spec/cassettes/resource/fetch_with_details_resource_info.yml +65 -0
  69. data/spec/cassettes/resource/fetch_with_file_and_mode_translations.yml +56 -0
  70. data/spec/cassettes/resource/fetch_with_file_translations.yml +56 -0
  71. data/spec/cassettes/resource/update_content_json.yml +115 -0
  72. data/spec/cassettes/resource/update_content_with_wrong_mimetype.yml +59 -0
  73. data/spec/cassettes/resource/update_content_yml.yml +114 -0
  74. data/spec/cassettes/resource/update_not_existing_resource.yml +55 -0
  75. data/spec/cassettes/resource/update_resource_info.yml +114 -0
  76. data/spec/cassettes/resource/update_source_language.yml +54 -0
  77. data/spec/cassettes/resource/update_source_string_metadata.yml +100 -0
  78. data/spec/cassettes/resource/update_translation_for_language.yml +62 -0
  79. data/spec/cassettes/resources/create_from_file.yml +55 -0
  80. data/spec/cassettes/resources/create_from_string.yml +54 -0
  81. data/spec/cassettes/resources/fetch_as_array.yml +62 -0
  82. data/spec/cassettes/resources/non_existing_project.yml +55 -0
  83. data/spec/cassettes/translation/fetch_string.yml +55 -0
  84. data/spec/cassettes/translation/fetch_strings.yml +54 -0
  85. data/spec/cassettes/translation/fetch_with_details_and_context_strings.yml +51 -0
  86. data/spec/cassettes/translation/fetch_with_details_and_key_strings.yml +56 -0
  87. data/spec/cassettes/translation/fetch_with_details_strings.yml +56 -0
  88. data/spec/cassettes/translation/update_multiple_translation_strings.yml +107 -0
  89. data/spec/cassettes/translation/update_single_translation_strings.yml +104 -0
  90. data/spec/cassettes/translation/update_string.yml +104 -0
  91. data/spec/lib/transifex/coordinators_spec.rb +22 -16
  92. data/spec/lib/transifex/formats_spec.rb +8 -8
  93. data/spec/lib/transifex/language_spec.rb +9 -10
  94. data/spec/lib/transifex/languages_spec.rb +8 -8
  95. data/spec/lib/transifex/project_language_spec.rb +41 -28
  96. data/spec/lib/transifex/project_languages_spec.rb +34 -18
  97. data/spec/lib/transifex/project_spec.rb +46 -73
  98. data/spec/lib/transifex/projects_spec.rb +72 -37
  99. data/spec/lib/transifex/resource_content_spec.rb +41 -24
  100. data/spec/lib/transifex/resource_source_spec.rb +21 -19
  101. data/spec/lib/transifex/resource_spec.rb +69 -41
  102. data/spec/lib/transifex/resources_spec.rb +42 -34
  103. data/spec/lib/transifex/reviewers_spec.rb +23 -17
  104. data/spec/lib/transifex/stats_spec.rb +20 -24
  105. data/spec/lib/transifex/translation_spec.rb +60 -38
  106. data/spec/lib/transifex/translation_string_spec.rb +26 -20
  107. data/spec/lib/transifex/translation_strings_spec.rb +65 -43
  108. data/spec/lib/transifex/translators_spec.rb +23 -17
  109. data/spec/lib/transifex_spec.rb +15 -0
  110. data/spec/lib/yaml/eo.yml +3 -0
  111. data/spec/spec_helper.rb +19 -83
  112. data/spec/support/client_helper.rb +8 -0
  113. data/spec/support/content_helper.rb +346 -0
  114. data/transifex-interface-ruby.gemspec +28 -25
  115. metadata +198 -21
  116. data/spec/lib/transifex/configuration_spec.rb +0 -17
  117. data/spec/lib/yaml/resource_translation_default_content_test.yml +0 -4
  118. data/spec/lib/yaml/resource_translation_reviewed_content_test.yml +0 -9
@@ -1,91 +1,64 @@
1
- require_relative '../../spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::Project do
4
-
3
+ describe Transifex::Project do
5
4
  describe "Manage a project" do
6
- before(:all) do
7
- @correct_params_private = {:slug => "projet_private", :name => "Projet de test Private", :description => "description", :source_language_code => "en", :private => true}
8
- @correct_params_public = {:slug => "projet_public", :name => "Projet de test Public", :description => "description", :source_language_code => "en", :repository_url => "http://en.google.com"}
9
- @private_project = Transifex::Projects.create(@correct_params_private)
10
- @public_project = Transifex::Projects.create(@correct_params_public)
11
- end
5
+ let(:project) { Transifex::Project.new("private-ruby-client") }
12
6
 
13
- describe "instanciation" do
7
+ describe "Instanciation" do
14
8
  it "should raise an error if a slug is not provided" do
15
9
  expect { Transifex::Project.new }.to raise_error(Transifex::MissingParametersError)
10
+ .with_message("The following attributes are missing: You must provide a slug for a project")
16
11
  end
17
- end
12
+ end
18
13
 
19
- context "private project" do
20
- describe "fetch" do
21
- it "should retrieve informations about the project without details" do
22
- fetched_project = @private_project.fetch
23
- expect { fetched_project = @private_project.fetch }.to_not raise_error
24
- expect(fetched_project).to be_a_kind_of(Hash)
25
- expect(fetched_project.keys).to contain_exactly("slug", "name", "description","source_language_code")
26
- end
27
- it "should retrieve informations about the project with details" do
28
- fetched_project = nil
29
- expect { fetched_project = @private_project.fetch_with_details }.to_not raise_error
30
- expect(fetched_project).to be_a_kind_of(Hash)
31
- expect(fetched_project.keys).to contain_exactly("archived", "auto_join", "fill_up_resources", "homepage", "last_updated", "long_description", "maintainers", "organization", "private", "resources", "tags", "team", "teams", "trans_instructions", "slug", "name", "description","source_language_code")
14
+ describe "Fetch" do
15
+ describe "#fetch" do
16
+ it "should retrieve the basic info about the project" do
17
+ VCR.use_cassette "project/fetch_private_project_info" do
18
+ expect(project.fetch).to eq(private_project_info)
19
+ end
32
20
  end
33
21
  end
34
- describe "update" do
35
- it "should not raise an error and update the project" do
36
- updated_project = nil
37
- expect { updated_project = @private_project.update({:description => "test"}) }.to_not raise_error
38
- expect(updated_project).to eq("OK")
39
- fetched_project = @private_project.fetch_with_details
40
- expect(fetched_project['description']).to eq('test')
41
- end
42
- it "should raise an error if updated field is wrong" do
43
- expect { @private_project.update({:buttchick => "lol"}) }.to raise_error(Transifex::TransifexError)
44
- end
45
- it "should raise an error if no paramaters to update are provided" do
46
- expect { @private_project.update }.to raise_error(Transifex::Error)
47
- end
48
- end
49
- describe "delete" do
50
- it "should not raise an error" do
51
- expect { @private_project.delete }.to_not raise_error
22
+
23
+ describe "#fetch_with_details" do
24
+ it "should retrieve the complete info about the project" do
25
+ VCR.use_cassette "project/fetch_with_details_private_project_info" do
26
+ expect(project.fetch_with_details).to eq(detailed_private_project_info)
27
+ end
52
28
  end
53
29
  end
54
30
  end
55
- context "public project" do
56
- describe "fetch" do
57
- it "should retrieve informations about the project without details" do
58
- fetched_project = nil
59
- expect { fetched_project = @public_project.fetch }.to_not raise_error
60
- expect(fetched_project).to be_a_kind_of(Hash)
61
- expect(fetched_project.keys).to contain_exactly("slug", "name", "description","source_language_code")
62
- end
63
- it "should retrieve informations about the project with details" do
64
- fetched_project = nil
65
- expect { fetched_project = @public_project.fetch_with_details }.to_not raise_error
66
- expect(fetched_project).to be_a_kind_of(Hash)
67
- expect(fetched_project.keys).to contain_exactly("archived", "auto_join", "fill_up_resources", "homepage", "last_updated", "long_description", "maintainers", "organization", "private", "resources", "tags", "team", "teams", "trans_instructions", "slug", "name", "description","source_language_code")
31
+
32
+ describe "Update" do
33
+ it "updates the project info" do
34
+ VCR.use_cassette "project/update_private_project" do
35
+ expect(project.update(description: "my new description")).to eq("OK")
36
+ expect(project.fetch_with_details).to include({"description" => "my new description"})
68
37
  end
69
38
  end
70
- describe "update" do
71
- it "should not raise an error and update the project" do
72
- updated_project = nil
73
- expect { updated_project = @public_project.update({:description => "test"}) }.to_not raise_error
74
- expect(updated_project).to eq("OK")
75
- end
76
- it "should raise an error if updated field is wrong" do
77
- updated_project = nil
78
- expect { updated_project = @public_project.update({:buttchick => "lol"}) }.to raise_error(Transifex::TransifexError)
39
+
40
+ it "should raise an error if the field to be updated is not allowed" do
41
+ VCR.use_cassette "project/update_non_existing_attribute_private_project" do
42
+ expect { project.update({non_existing_attribute: "blah"}) }.to raise_error(Transifex::TransifexError)
43
+ .with_message("Field 'non_existing_attribute' is not allowed.")
79
44
  end
80
- it "should raise an error if no paramaters to update are provided" do
81
- expect { @public_project.update }.to raise_error(Transifex::Error)
45
+ end
46
+
47
+ it "should raise an error if no paramaters to update are provided" do
48
+ VCR.use_cassette "project/update_with_missing_params_private_project" do
49
+ expect { project.update }.to raise_error(Transifex::Error)
50
+ .with_message("Empty request")
82
51
  end
83
52
  end
84
- describe "delete" do
85
- it "should not raise an error" do
86
- expect { @public_project.delete }.to_not raise_error
87
- end
53
+ end
54
+
55
+ describe "Delete" do
56
+ it "should delete the project" do
57
+ VCR.use_cassette "project/delete_project" do
58
+ expect(project.delete).to be nil
59
+ expect { project.fetch }.to raise_error(Transifex::TransifexError).with_message("Not Found")
60
+ end
88
61
  end
89
- end
90
- end
91
- end
62
+ end
63
+ end
64
+ end
@@ -1,48 +1,83 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::Projects do
4
- before(:all) do
5
- @incorrect_params = {:slug => "test"}
6
- @correct_params_private = {:slug => "projet_de_test_private", :name => "Projet de test Public", :description => "description", :source_language_code => "en", :private => true}
7
- @correct_params_public = {:slug => "projet_de_test_public", :name => "Projet de test Private", :description => "description", :source_language_code => "en", :repository_url => "http://en.google.com"}
8
- end
3
+ describe Transifex::Projects do
4
+
5
+ describe "Create" do
6
+ it "should raise an error if parameters are missing" do
7
+ expect { Transifex::Projects.create(slug: "private-ruby-client") }
8
+ .to raise_error(Transifex::MissingParametersError)
9
+ .with_message("The following attributes are missing: name, description, source_language_code, repository_url, private")
10
+ end
11
+
12
+ it "creates a private project" do
13
+ params = {
14
+ slug: "private-ruby-client",
15
+ name: "Private Ruby Client",
16
+ description: "Private Ruby Client",
17
+ source_language_code: "eo",
18
+ private: true
19
+ }
9
20
 
10
- describe "create" do
11
- it "should raise an error if required parameters are missing" do
12
- expect { Transifex::Projects.create(@incorrect_params) }.to raise_error(Transifex::MissingParametersError)
13
- end
14
- context "private project" do
15
- it "should not raise an error if required parameters are provided and create the private project" do
16
- created_project = nil
17
- expect { created_project = Transifex::Projects.create(@correct_params_private) }.to_not raise_error
18
- expect(created_project).to be_a_kind_of(Transifex::Project)
19
- expect(created_project.project_slug).to eq(@correct_params_private[:slug])
20
- created_project.delete
21
+ VCR.use_cassette "projects/create_private_project" do
22
+ project = Transifex::Projects.create(params)
23
+
24
+ expect(project.project_slug).to eq(params[:slug])
25
+ expect(Transifex::Project.new(params[:slug]).fetch).to eq(private_project_info)
21
26
  end
22
27
  end
23
- context "public project" do
24
- it "should not raise an error if required parameters are provided and create the project" do
25
- created_project = nil
26
- expect { created_project = Transifex::Projects.create(@correct_params_public) }.to_not raise_error
27
- expect(created_project).to be_a_kind_of(Transifex::Project)
28
- expect(created_project.project_slug).to eq(@correct_params_public[:slug])
29
- created_project.delete
28
+
29
+ it "raises an error if a project with the same slug already exists" do
30
+ params = {
31
+ slug: "private-ruby-client",
32
+ name: "Private Ruby Client",
33
+ description: "Private Ruby Client",
34
+ source_language_code: "eo",
35
+ private: true
36
+ }
37
+
38
+ VCR.use_cassette "projects/create_used_slug_project" do
39
+ expect { Transifex::Projects.create(params) }.to raise_error(Transifex::TransifexError)
40
+ .with_message("[u\"[('slug', [u'Project with this Slug already exists.'])]\"]")
30
41
  end
31
- it "should raise an error if repository_url is not matching the correct format" do
32
- incorrect_params_public = @correct_params_public
33
- incorrect_params_public[:repository_url] = "www.google.com"
34
- expect { Transifex::Projects.create(@correct_params_public) }.to raise_error(Transifex::ParametersFormatError)
42
+ end
43
+
44
+ it "creates a public project" do
45
+ params = {
46
+ slug: "public-ruby-client",
47
+ name: "Public Ruby Client",
48
+ description: "Public Ruby Client",
49
+ source_language_code: "it",
50
+ repository_url: "http://valid.url.it"
51
+ }
52
+
53
+ VCR.use_cassette "projects/create_public_project" do
54
+ project = Transifex::Projects.create(params)
55
+
56
+ expect(project.project_slug).to eq(params[:slug])
57
+ expect(Transifex::Project.new(params[:slug]).fetch).to eq(public_project_info)
35
58
  end
36
59
  end
60
+
61
+ it "should raise an error if repository_url is not matching the requested format" do
62
+ params = {
63
+ slug: "public-ruby-client",
64
+ name: "Public Ruby Client",
65
+ description: "Public Ruby Client",
66
+ source_language_code: "it",
67
+ repository_url: "http://not-valid.url"
68
+ }
69
+
70
+ expect { Transifex::Projects.create(params) }
71
+ .to raise_error(Transifex::ParametersFormatError)
72
+ .with_message("The following parameter: repository_url must follow the format: http|https|ftp://x.x.x")
73
+ end
37
74
  end
75
+
38
76
  describe "Fetch" do
39
- it "should not raise an error and return an array of hash" do
40
- fetched_projects = nil
41
- expect{ fetched_projects = Transifex::Projects.fetch}.to_not raise_error
42
- expect(fetched_projects).to be_a_kind_of(Array)
43
- expect(fetched_projects).not_to match_array([])
44
- expect(fetched_projects.first).to be_a_kind_of(Hash)
45
- expect(fetched_projects.first.keys).to contain_exactly("slug", "name", "description","source_language_code")
77
+ it "retrieves the projects as an array of hashes, one for each project" do
78
+ VCR.use_cassette "projects/fetch_projects" do
79
+ expect(Transifex::Projects.fetch).to eq(all_projects_info)
80
+ end
46
81
  end
47
82
  end
48
- end
83
+ end
@@ -1,40 +1,57 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::Content do
4
- before(:all) do
5
- @project = Transifex::Project.new("projet-de-test-1")
6
- @resource = @project.resource("test")
7
- end
3
+ describe Transifex::ResourceComponents::Content do
4
+ let(:project) { Transifex::Project.new("ruby-client") }
5
+ let(:resource) { project.resource("test") }
8
6
 
9
- describe "Instanciation" do
10
- it "should raise an error when no parameters given" do
7
+ describe "Instantiation" do
8
+ it "should raise an error when no parameters are given" do
11
9
  expect{ Transifex::ResourceComponents::Content.new }.to raise_error(ArgumentError)
12
10
  end
13
11
  end
14
12
 
15
13
  describe "Fetch" do
16
14
  it "should retrieve the resource content as a hash" do
17
- resource_content = nil
18
- expect{ resource_content = @resource.content.fetch }.to_not raise_error
19
- expect(resource_content).to be_a_kind_of(Hash)
20
- expect(resource_content.keys).to contain_exactly("content", "mimetype")
21
- end
15
+ VCR.use_cassette "resource/fetch_content_as_hash" do
16
+ expect(resource.content.fetch).to eq resource_content_hash
17
+ end
18
+ end
22
19
 
23
20
  it "should retrieve the resource content as a file" do
24
- resource_content = nil
25
- path_to_file = File.dirname(__FILE__) + "/../yaml/resource_content_test.yml"
26
- expect{ resource_content = @resource.content.fetch_with_file(path_to_file) }.to_not raise_error
27
- file_exist = File.file?(path_to_file)
28
- expect(file_exist).to eq(true)
29
- end
21
+ VCR.use_cassette "resource/fetch_content_as_file" do
22
+ resource.content.fetch_with_file("fetched.yml")
23
+ end
24
+
25
+ expect(File.exist?("fetched.yml")).to be true
26
+ end
30
27
  end
31
28
 
32
29
  describe "Update" do
33
- it "should not raise an error and update the resource content" do
34
- expect{ @resource.content.update({:i18n_type => "YAML", :content => get_yaml_source_trad_file_path('en')}) }.to_not raise_error
30
+ it "updates a resource using a file" do
31
+ params = { i18n_type: "YAML", content: get_yaml_source_trad_file_path("eo") }
32
+ options = { trad_from_file: true }
33
+
34
+ VCR.use_cassette "resource/update_content_yml" do
35
+ expect(resource.content.update(params, options))
36
+ .to eq updated_resource_with_file
37
+ end
35
38
  end
36
- it "should raise an error if updated resource content is of a different type than the previous" do
37
- expect{ @resource.content.update({:i18n_type => "TXT", :content => get_yaml_source_trad_file_path('en')}) }.to raise_error(Transifex::Error)
39
+
40
+ it "updates a resource using json" do
41
+ json_resource = project.resource("json")
42
+ params = {i18n_type: "KEYVALUEJSON", content: {test_string: 'test string as json'}}
43
+
44
+ VCR.use_cassette "resource/update_content_json" do
45
+ expect(json_resource.content.update(params))
46
+ .to eq updated_resource_with_json
47
+ end
48
+ end
49
+
50
+ it "should raise an error if the mime type of the resource to be updated is different than the one defined in the project for the resource" do
51
+ VCR.use_cassette "resource/update_content_with_wrong_mimetype" do
52
+ expect { resource.content.update(i18n_type: "TXT", content: "") }.to raise_error(Transifex::Error)
53
+ .with_message("You must use the mimetype YML to upload a new resource file")
54
+ end
38
55
  end
39
56
  end
40
- end
57
+ end
@@ -1,30 +1,32 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::Source do
4
- before(:all) do
5
- @project = Transifex::Project.new("projet-de-test-1")
6
- @resource = @project.resource("test")
7
- end
3
+ describe Transifex::ResourceComponents::Source do
4
+ let(:project) { Transifex::Project.new("ruby-client") }
5
+ let(:resource) { project.resource("json") }
8
6
 
9
- describe "Instanciation" do
10
- it "should raise an error when no parameters given" do
11
- expect{ Transifex::ResourceComponents::Source.new }.to raise_error(Transifex::MissingParametersError)
7
+ describe "Instantiation" do
8
+ it "should raise an error if the project_slug is not provided" do
9
+ expect { Transifex::ResourceComponents::Source.new }.to raise_error(Transifex::MissingParametersError)
10
+ .with_message("The following attributes are missing: project_slug")
12
11
  end
13
12
  end
14
13
 
15
14
  describe "Fetch" do
16
- it "should retrieve the resource source string details as a hash" do
17
- source_string_details = nil
18
- expect{ source_string_details = @resource.source("routes.mercury_editor").fetch }.to_not raise_error
19
- expect(source_string_details).to be_a_kind_of(Hash)
20
- expect(source_string_details.keys).to contain_exactly("comment", "character_limit", "tags")
21
- end
15
+ it "should retrieve the meta-data of a resource source string" do
16
+ VCR.use_cassette "resource/fetch_source_string_metadata" do
17
+ expect(resource.source("content.update_string").fetch).to eq resource_source_string_metadata
18
+ end
19
+ end
22
20
  end
23
21
 
24
22
  describe "Update" do
25
- it "should not raise an error and update the source string details" do
26
- params = {:comment => "test", :character_limit => 140, :tags => ["tag1", "tag2"]}
27
- expect{ @resource.source("routes.mercury_editor").update(params) }.to_not raise_error
23
+ it "should update the meta-data of a resource source string" do
24
+ params = {comment: "my comment", character_limit: 140, tags: ["tag1", "tag2"]}
25
+
26
+ VCR.use_cassette "resource/update_source_string_metadata" do
27
+ expect(resource.source("content.update_string").update(params)).to eq "OK"
28
+ expect(resource.source("content.update_string").fetch).to eq updated_resource_source_string_metadata
29
+ end
28
30
  end
29
31
  end
30
- end
32
+ end
@@ -1,66 +1,94 @@
1
- require_relative '../../spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::Resource do
3
+ describe Transifex::Resource do
4
+ let(:project) { Transifex::Project.new("ruby-client") }
4
5
 
5
- before(:all) do
6
- @correct_params_public = {:slug => "resource_test_project", :name => "Projet de test resource", :description => "description", :source_language_code => "en", :repository_url => "http://en.google.com"}
7
- @project = Transifex::Projects.create(@correct_params_public)
8
- @project.resources.create({:slug => "resource_test", :name => "resource_test", :i18n_type => "TXT", :content => "test"})
9
- end
6
+ describe "Instantiation" do
7
+ it "should raise an error if the project_slug is not provided" do
8
+ expect { Transifex::Resource.new }.to raise_error(Transifex::MissingParametersError)
9
+ .with_message("The following attributes are missing: project_slug")
10
+ end
10
11
 
11
- it "should raise an error if project slug or Resource slug are not provided" do
12
- expect{ Transifex::Resource.new(nil, "test") }.to raise_error(Transifex::MissingParametersError)
13
- expect{ Transifex::Resource.new("test", nil) }.to raise_error(Transifex::MissingParametersError)
12
+ it "should raise an error if the resource_slug is not provided" do
13
+ expect { Transifex::Resource.new("test", nil) }.to raise_error(Transifex::MissingParametersError)
14
+ .with_message("The following attributes are missing: resource_slug")
15
+ end
14
16
  end
15
17
 
16
18
  describe "Fetch" do
17
- it "should raise an error if resource doesn't exist" do
18
- expect{ @project.resource("wrong_slug").fetch }.to raise_error(Transifex::Error)
19
+ it "should raise an error if the resource doesn't exist" do
20
+ VCR.use_cassette "resource/fetch_not_existing_resource" do
21
+ expect { project.resource("not_existing_resource").fetch }.to raise_error(Transifex::Error)
22
+ .with_message("Not Found")
23
+ end
19
24
  end
20
25
 
21
- it "should not raise an error and retrieve the correct infos without details" do
22
- fetched_resource = nil
23
- expect{ fetched_resource = @project.resource("resource_test").fetch }.to_not raise_error
24
- expect(fetched_resource).to be_a_kind_of(Hash)
25
- expect(fetched_resource.keys).to contain_exactly("source_language_code", "name", "i18n_type", "priority", "slug", "categories")
26
+ describe "#fetch" do
27
+ it "should retrieve the basic info for the resource" do
28
+ resource = project.resource("json")
29
+
30
+ VCR.use_cassette "resource/fetch_resource_info" do
31
+ expect(resource.fetch).to eq basic_resource_info
32
+ end
33
+ end
26
34
  end
27
35
 
28
- it "should not raise an error and retrieve the correct infos with details" do
29
- fetched_resource = nil
30
- expect{ fetched_resource = @project.resource("resource_test").fetch_with_details }.to_not raise_error
31
- expect(fetched_resource).to be_a_kind_of(Hash)
32
- expect(fetched_resource.keys).to contain_exactly("source_language_code", "name", "created", "wordcount", "i18n_type", "project_slug", "accept_translations", "last_update", "priority", "available_languages", "total_entities", "slug", "categories")
36
+ describe "#fetch_with_details" do
37
+ it "should retrieve the complete info for the resource" do
38
+ resource = project.resource("json")
39
+
40
+ VCR.use_cassette "resource/fetch_with_details_resource_info" do
41
+ expect(resource.fetch_with_details).to eq detailed_resource_info
42
+ end
43
+ end
33
44
  end
34
45
  end
35
46
 
36
47
  describe "Update" do
37
- it "should raise an error if resource doesn't exist" do
38
- expect{ @project.resource("wrong_slug").update }.to raise_error(Transifex::Error)
48
+ it "should raise an error if the resource doesn't exist" do
49
+ params = {name: "new name"}
50
+
51
+ VCR.use_cassette "resource/update_not_existing_resource" do
52
+ expect { project.resource("not_existing_resource").update(params) }.to raise_error(Transifex::Error)
53
+ .with_message("Not Found")
54
+ end
39
55
  end
40
56
 
41
- it "should update multiple attributes" do
42
- expect{ fetched_resource = @project.resource("resource_test").update({name: "new_name", categories: ["test1", "test2"]}) }.to_not raise_error
43
- fetched_resource = @project.resource("resource_test").fetch
44
- expect(fetched_resource['name']).to eq("new_name")
45
- expect(fetched_resource['categories']).to be_a_kind_of(Array)
46
- expect(fetched_resource['categories'].join(',')).to eq("test1,test2")
57
+ it "should update the resource when given multiple changes" do
58
+ resource = project.resource("test")
59
+
60
+ params = {name: "updated name", categories: ["test1", "test2"]}
61
+
62
+ VCR.use_cassette "resource/update_resource_info" do
63
+ expect(resource.update(params)).to eq "OK"
64
+
65
+ expect(resource.fetch).to eq updated_resource_info
66
+ end
47
67
  end
48
68
  end
49
69
 
50
70
  describe "Delete" do
51
- it "should raise an error if resource doesn't exist" do
52
- expect{ @project.resource("wrong_slug").delete }.to raise_error(Transifex::Error)
71
+ it "should raise an error if the resource doesn't exist" do
72
+ VCR.use_cassette "resource/delete_not_existing_resource" do
73
+ expect { project.resource("not_existing_resource").delete }.to raise_error(Transifex::Error)
74
+ .with_message("Not Found")
75
+ end
53
76
  end
54
77
 
55
78
  it "should delete a resource" do
56
- @project.resources.create({:slug => "resource_delete_test", :name => "resource_delete_test", :i18n_type => "TXT", :content => "test"})
57
- expect{ @project.resource("resource_delete_test").fetch }.to_not raise_error
58
- expect{ @project.resource("resource_delete_test").delete }.to_not raise_error
59
- expect{ @project.resource("resource_delete_test").fetch }.to raise_error
60
- end
61
- end
79
+ VCR.use_cassette "resource/delete_resource" do
80
+ project.resources.create(
81
+ slug: "resource_to_be_deleted",
82
+ name: "Resource to be deleted",
83
+ i18n_type: "TXT",
84
+ content: "nothing to see here"
85
+ )
86
+
87
+ expect(project.resource("resource_to_be_deleted").delete).to be nil
62
88
 
63
- after(:all) do
64
- @project.delete
89
+ expect { project.resource("resource_to_be_deleted").fetch }.to raise_error(Transifex::Error)
90
+ .with_message("Not Found")
91
+ end
92
+ end
65
93
  end
66
- end
94
+ end