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,50 +1,58 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::Resources do
3
+ describe Transifex::Resources do
4
+ let(:project) { Transifex::Project.new("ruby-client") }
4
5
 
5
- before(:all) do
6
- @correct_project = Transifex::Project.new("projet-de-test-1")
7
- @wrong_project = Transifex::Project.new("lll")
8
- end
9
-
10
- it "should raise an error if instanciated without a project_slug" do
11
- expect{ Transifex::Resources.new() }.to raise_error(Transifex::MissingParametersError)
6
+ describe "Instantiation" do
7
+ it "should raise an error if the project_slug is not provided" do
8
+ expect { Transifex::Resources.new }.to raise_error(Transifex::MissingParametersError)
9
+ .with_message("The following attributes are missing: project_slug")
10
+ end
12
11
  end
13
12
 
14
13
  describe "Fetch" do
15
- it "should not raise any error and return a hash" do
16
- resources_instance = @correct_project.resources
17
- fetched_resources = nil
18
- expect{ fetched_resources = resources_instance.fetch }.to_not raise_error
19
- expect(fetched_resources).to be_a_kind_of(Array)
20
- expect(fetched_resources.first).to be_a_kind_of(Hash)
21
- expect(fetched_resources.first.keys).to contain_exactly("source_language_code", "name", "i18n_type", "priority", "slug", "categories")
14
+ it "should retrieve the resources as an array of hashes, one for each resource" do
15
+ VCR.use_cassette "resources/fetch_as_array" do
16
+ expect(project.resources.fetch).to eq all_project_resources_array
17
+ end
22
18
  end
23
19
 
24
- it "should raise an error if project doesn't exist" do
25
- resources_instance = @wrong_project.resources
26
- fetched_resources = nil
27
- expect{ fetched_resources = resources_instance.fetch }.to raise_error(Transifex::TransifexError)
20
+ it "should raise an error if the project doesn't exist" do
21
+ non_existing_project = Transifex::Project.new("not_existing_project")
22
+
23
+ VCR.use_cassette "resources/non_existing_project" do
24
+ expect { non_existing_project.resources.fetch }.to raise_error(Transifex::TransifexError)
25
+ .with_message("Not Found")
26
+ end
28
27
  end
29
28
  end
30
29
 
31
30
  describe "Create" do
32
- it "should raise an error if required parameters are missing" do
33
- expect{ @correct_project.resources.create }.to raise_error(Transifex::MissingParametersError)
34
- end
35
-
36
- it "should create a new resource for the project without using a file" do
37
- expect{ @correct_project.resources.create({:slug => "p", :name => "without_file", :i18n_type => "TXT", :content => "test"}) }.to_not raise_error
31
+ it "should raise an error if the required parameters are missing" do
32
+ expect { project.resources.create }.to raise_error(Transifex::MissingParametersError)
33
+ .with_message("The following attributes are missing: slug, name, i18n_type, content")
38
34
  end
39
35
 
40
- it "should create a new resource for the project using a file" do
41
- options = {:trad_from_file => true}
42
- expect{ @correct_project.resources.create({:slug => "q", :name => "with_file", :i18n_type => "YAML", :content => get_yaml_source_trad_file_path('en')}, options) }.to_not raise_error
36
+ it "should create a new resource in the project without using a file" do
37
+ resource_attributes = {slug: "string_resource", name: "without file", i18n_type: "TXT", content: "test"}
38
+
39
+ VCR.use_cassette "resources/create_from_string" do
40
+ expect(project.resources.create(resource_attributes)).to eq successful_resource_creation
41
+ end
43
42
  end
44
- end
45
43
 
46
- after(:all) do
47
- @correct_project.resource("q").delete
48
- @correct_project.resource("p").delete
44
+ it "should create a new resource in the project using a file" do
45
+ resource_attributes = {
46
+ slug: "file_resource",
47
+ name: "with file",
48
+ i18n_type: "YML",
49
+ content: get_yaml_source_trad_file_path("eo")
50
+ }
51
+ options = {trad_from_file: true}
52
+
53
+ VCR.use_cassette "resources/create_from_file" do
54
+ expect(project.resources.create(resource_attributes, options)).to eq successful_resource_creation
55
+ end
56
+ end
49
57
  end
50
- end
58
+ end
@@ -1,32 +1,38 @@
1
- require_relative '../../spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Transifex::ProjectComponents::LanguageComponents::Reviewers do
4
- before(:all) do
5
- @project = Transifex::Project.new("projet-de-test-1")
6
- end
4
+ let(:project) { Transifex::Project.new("ruby-client") }
7
5
 
8
- describe "Instanciation" do
9
- it "should raise an error when no parameters given" do
10
- expect{ Transifex::ProjectComponents::LanguageComponents::Reviewers.new }.to raise_error(Transifex::MissingParametersError)
6
+ describe "Instantiation" do
7
+ it "should raise an error if the project_slug is not provided" do
8
+ expect{ Transifex::ProjectComponents::LanguageComponents::Reviewers.new }
9
+ .to raise_error(Transifex::MissingParametersError)
10
+ .with_message("The following attributes are missing: project_slug")
11
11
  end
12
12
  end
13
13
 
14
14
  describe "Fetch" do
15
- it "should not raise an error and retrieve the language's informations" do
16
- language_coordinators_infos = nil
17
- expect{ language_coordinators_infos = @project.language('en').reviewers.fetch }.to_not raise_error
18
- expect(language_coordinators_infos).to be_a_kind_of(Hash)
19
- expect(language_coordinators_infos.keys).to contain_exactly("reviewers")
15
+ it "retrieves the language reviewers" do
16
+ VCR.use_cassette "project/language/fetch_reviewers" do
17
+ expect(project.language("en").reviewers.fetch).to eq({"reviewers" => ["wirido"]})
18
+ end
20
19
  end
21
20
  end
22
21
 
23
22
  describe "Update" do
24
- it "should not raise an error and update the coordinators list" do
25
- expect{ @project.language('en').reviewers.update(['fredericgrais'])}.to_not raise_error
23
+ it "updates the reviewers list" do
24
+ VCR.use_cassette "project/language/update_reviewers" do
25
+ expect(project.language("en").reviewers.update(["mupo"])).to eq("OK")
26
+ expect(project.language("en").reviewers.fetch).to eq({"reviewers" => ["mupo"]})
27
+ end
26
28
  end
27
29
 
28
- it "should raise an error if the coordinator doesn't exist" do
29
- expect{ @project.language('en').reviewers.update(['grgrgef'])}.to raise_error(Transifex::TransifexError)
30
+ it "should raise an error if the reviewer doesn't exist" do
31
+ VCR.use_cassette "project/language/update_non_existing_reviewer" do
32
+ expect { project.language("en").reviewers.update(['not_existing_reviewer'])}
33
+ .to raise_error(Transifex::TransifexError)
34
+ .with_message("Users not_existing_reviewer do not exist.")
35
+ end
30
36
  end
31
37
  end
32
- end
38
+ end
@@ -1,34 +1,30 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::Stats 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::Stats do
4
+ let(:project) { Transifex::Project.new("ruby-client") }
8
5
 
9
- describe "Instanciation" do
6
+ describe "Instantiation" do
10
7
  it "should raise an error when no parameters given" do
11
- expect{ Transifex::ResourceComponents::Stats.new }.to raise_error(ArgumentError)
8
+ expect { Transifex::ResourceComponents::Stats.new }.to raise_error(ArgumentError)
12
9
  end
13
10
  end
14
11
 
15
12
  describe "Fetch" do
16
- it "should retrieve the stats for all languages as a hash" do
17
- resource_stats = nil
18
- resource_details = @project.resource("test").fetch_with_details
19
- resource_available_languages = resource_details["available_languages"].map{|language| language["code"]}
20
- expect{ resource_stats = @resource.statistics.fetch }.to_not raise_error
21
- expect(resource_stats).to be_a_kind_of(Hash)
22
- expect(resource_stats.keys).to match_array(resource_available_languages)
23
- end
24
- it "should retrieve the stats for a specific language as a hash" do
25
- resource_stats = nil
26
- expect{ resource_stats = @resource.statistics.fetch("en") }.to_not raise_error
27
- expect(resource_stats).to be_a_kind_of(Hash)
28
- expect(resource_stats.keys).to contain_exactly("reviewed_percentage", "completed", "untranslated_words", "last_commiter", "reviewed", "translated_entities", "translated_words", "last_update", "untranslated_entities")
13
+ it "should retrieve the stats of a resource for all languages as a hash" do
14
+ VCR.use_cassette "resource/fetch_all_languages_stats" do
15
+ expect(project.resource("test").statistics.fetch).to eq all_languages_stats
16
+ end
29
17
  end
30
- end
31
-
32
18
 
19
+ it "should retrieve the stats of a resource for a specific language as a hash" do
20
+ Transifex.configure do |c|
21
+ c.client_login = "m.giambitto@freegoweb.it"
22
+ c.client_secret = "molli_01"
23
+ end
33
24
 
34
- end
25
+ VCR.use_cassette "resource/fetch_language_stats" do
26
+ expect(project.resource("test").statistics.fetch("en")).to eq all_languages_stats["en"]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,53 +1,75 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::Translation 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::Translation 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
11
- expect{ Transifex::ResourceComponents::Translation.new }.to raise_error(Transifex::MissingParametersError)
7
+ describe "Instantiation" do
8
+ it "should raise an error if the project_slug is missing" do
9
+ expect { Transifex::ResourceComponents::Translation.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 raise an error if no language code is provided" do
17
- expect{ resource_stats = @resource.translation.fetch }.to raise_error(Transifex::MissingParametersError)
18
- end
19
- it "should retrieve the translation content as a hash" do
20
- translation_content = nil
21
- expect{ translation_content = @resource.translation('en').fetch }.to_not raise_error
22
- expect(translation_content).to be_a_kind_of(Hash)
23
- expect(translation_content.keys).to contain_exactly("content", "mimetype")
15
+ describe "#fetch" do
16
+ it "should raise an error if no language code is provided" do
17
+ VCR.use_cassette "resource/fetch_without_language_code_translations" do
18
+ expect { resource.translation.fetch }.to raise_error(Transifex::MissingParametersError)
19
+ .with_message("The following attributes are missing: translation_slug")
20
+ end
21
+ end
22
+
23
+ it "should retrieve a resource translation content as a hash" do
24
+ VCR.use_cassette "resource/fetch_translations" do
25
+ expect(resource.translation("en").fetch).to eq translation_content
26
+ end
27
+ end
24
28
  end
25
- it "should retrieve the translation content as a file with default mode" do
26
- translation_content = nil
27
- path_to_file = File.dirname(__FILE__) + "/../yaml/resource_translation_default_content_test.yml"
28
- options = {:path_to_file => path_to_file}
29
- expect{ translation_content = @resource.translation('fr').fetch_with_file(options) }.to_not raise_error
30
- file_exist = File.file?(path_to_file)
31
- expect(file_exist).to eq(true)
32
- end
33
- it "should retrieve the translation content as a file with a mode" do
34
- translation_content = nil
35
- path_to_file = File.dirname(__FILE__) + "/../yaml/resource_translation_reviewed_content_test.yml"
36
- options = {:path_to_file => path_to_file, :mode => "reviewed"}
37
- expect{ translation_content = @resource.translation('en').fetch_with_file(options) }.to_not raise_error
38
- file_exist = File.file?(path_to_file)
39
- expect(file_exist).to eq(true)
29
+
30
+ describe "#fetch_with_file" do
31
+ it "should retrieve the translation content as a file with default mode" do
32
+ path_to_file = "translations.yml"
33
+ options = {path_to_file: path_to_file}
34
+
35
+ VCR.use_cassette "resource/fetch_with_file_translations" do
36
+ resource.translation("en").fetch_with_file(options)
37
+
38
+ expect(File.exist?(path_to_file)).to be true
39
+ expect(File.read(path_to_file)).to eq file_translation_content
40
+ end
41
+ end
42
+
43
+ it "should retrieve the translation content as a file with a specific mode" do
44
+ path_to_file = "translations.yml"
45
+ options = {path_to_file: path_to_file, mode: "translator"}
46
+
47
+ VCR.use_cassette "resource/fetch_with_file_and_mode_translations" do
48
+ resource.translation("en").fetch_with_file(options)
49
+
50
+ expect(File.exist?(path_to_file)).to be true
51
+ expect(File.read(path_to_file)).to eq file_translation_content_with_mode
52
+ end
53
+ end
40
54
  end
41
55
  end
42
56
 
43
57
  describe "Update" do
44
58
  it "sould raise an error if try to update source language" do
45
- options = {:i18n_type => "YAML", :content => get_yaml_source_trad_file_path('en')}
46
- expect{ translation_content = @resource.translation('en').update(options) }.to raise_error(Transifex::TransifexError)
59
+ options = {i18n_type: "YAML", content: get_yaml_source_trad_file_path("eo")}
60
+
61
+ VCR.use_cassette "resource/update_source_language" do
62
+ expect { resource.translation("eo").update(options) }.to raise_error(Transifex::TransifexError)
63
+ .with_message("Cannot update the source language")
64
+ end
47
65
  end
48
- it "should not raise an error and update the resource translation" do
49
- options = {:i18n_type => "YAML", :content => get_yaml_source_trad_file_path('fr')}
50
- expect{ @resource.translation('fr').update(options) }.to_not raise_error
66
+
67
+ it "should update the resource translation" do
68
+ options = {i18n_type: "YAML", content: get_yaml_source_trad_file_path("en")}
69
+
70
+ VCR.use_cassette "resource/update_translation_for_language" do
71
+ expect(resource.translation("en").update(options)).to eq updated_translations
72
+ end
51
73
  end
52
74
  end
53
- end
75
+ end
@@ -1,33 +1,39 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::TranslationComponents::String 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::TranslationComponents::String 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
11
- expect{ Transifex::ResourceComponents::TranslationComponents::String.new }.to raise_error(Transifex::MissingParametersError)
7
+ describe "Instantiation" do
8
+ it "should raise an error if the translation key is not provided" do
9
+ expect { Transifex::ResourceComponents::TranslationComponents::String.new }
10
+ .to raise_error(Transifex::MissingParametersError)
11
+ .with_message("The following attributes are missing: translation_key")
12
12
  end
13
13
  end
14
14
 
15
15
  describe "Fetch" do
16
- it "should raise an error if no key provided" do
17
- expect{ retrieved_details = @resource.translation('en').string.fetch }.to raise_error(Transifex::MissingParametersError)
16
+ it "should raise an error if the key is not provided" do
17
+ expect { resource.translation("en").string.fetch }
18
+ .to raise_error(Transifex::MissingParametersError)
19
+ .with_message("The following attributes are missing: key")
18
20
  end
19
- it "should not raise an error and retrieve the details of the string" do
20
- retrieved_details = nil
21
- expect{ retrieved_details = @resource.translation('en').string('routes.mercury_editor').fetch }.to_not raise_error
22
- expect(retrieved_details).to be_a_kind_of(Hash)
23
- expect(retrieved_details.keys).to contain_exactly("comment", "context", "tags", "character_limit", "user", "key", "reviewed", "pluralized", "source_string", "translation", "last_update", "occurrences")
21
+
22
+ it "retrieve the details of the string" do
23
+ VCR.use_cassette "translation/fetch_string" do
24
+ expect(resource.translation("en").string("test_string").fetch).to eq string_details
25
+ end
24
26
  end
25
27
  end
26
28
 
27
29
  describe "Update" do
28
- it "should not raise an error and update the specified translation string" do
29
- params = {:reviewed => true, :translation => "Pouet"}
30
- expect{ @resource.translation('fr').string('routes.mercury_editor').update(params) }.to_not raise_error
30
+ it "update the specified translation string" do
31
+ params = {reviewed: true, translation: "translated test string"}
32
+
33
+ VCR.use_cassette "translation/update_string" do
34
+ expect(resource.translation("en").string("test_string").update(params)).to eq "OK"
35
+ expect(resource.translation("en").string("test_string").fetch["translation"]).to eq params[:translation]
36
+ end
31
37
  end
32
38
  end
33
- end
39
+ end
@@ -1,57 +1,79 @@
1
- require_relative "../../spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe Transifex::ResourceComponents::TranslationComponents::Strings 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::TranslationComponents::Strings 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
11
- expect{ Transifex::ResourceComponents::TranslationComponents::Strings.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::TranslationComponents::Strings.new }
10
+ .to raise_error(Transifex::MissingParametersError)
11
+ .with_message("The following attributes are missing: project_slug")
12
12
  end
13
13
  end
14
14
 
15
15
  describe "Fetch" do
16
- it "should not raise an error and retrieve the strings of the translation without details" do
17
- retrieved_strings = nil
18
- expect{ retrieved_strings = @resource.translation('en').strings.fetch }.to_not raise_error
19
- expect(retrieved_strings).to be_a_kind_of(Array)
20
- expect(retrieved_strings.first.keys).to contain_exactly("comment", "context", "key", "reviewed", "pluralized", "source_string", "translation")
21
- end
22
- it "should not raise an error and retrieve the strings of the translation with details" do
23
- retrieved_strings = nil
24
- expect{ retrieved_strings = @resource.translation('en').strings.fetch_with_details }.to_not raise_error
25
- expect(retrieved_strings).to be_a_kind_of(Array)
26
- expect(retrieved_strings.first.keys).to contain_exactly("comment", "context", "tags", "character_limit", "user", "key", "reviewed", "pluralized", "source_string", "translation", "last_update", "occurrences")
27
- end
28
- it "should not raise an error and retrieve the strings of the translation with the key" do
29
- retrieved_strings = nil
30
- options = {:key => "routes.mercury_editor"}
31
- expect{ retrieved_strings = @resource.translation('en').strings.fetch_with_details(options) }.to_not raise_error
32
- expect(retrieved_strings).to be_a_kind_of(Array)
33
- expect(retrieved_strings.first.keys).to contain_exactly("comment", "context", "tags", "character_limit", "user", "key", "reviewed", "pluralized", "source_string", "translation", "last_update", "occurrences")
34
- end
35
- it "should not raise an error and return an empty hash if researched context doesn't exist" do
36
- retrieved_strings = nil
37
- options = {:context => "notexist"}
38
- expect{ retrieved_strings = @resource.translation('en').strings.fetch(options) }.to_not raise_error
39
- expect(retrieved_strings).to be_a_kind_of(Array)
40
- empty_array = retrieved_strings.empty?
41
- expect(empty_array).to eq(true)
16
+ describe "#fetch" do
17
+ it "retrieves the translations of all the strings of a resource for a certain language" do
18
+ VCR.use_cassette "translation/fetch_strings" do
19
+ expect(resource.translation("en").strings.fetch).to eq language_strings
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#fetch_with_details" do
25
+ it "retrieves the detailed translations of all the strings of a resource for a certain language" do
26
+ VCR.use_cassette "translation/fetch_with_details_strings" do
27
+ expect(resource.translation("en").strings.fetch_with_details).to eq language_strings_with_details
28
+ end
29
+ end
30
+ end
31
+
32
+ it "retrieves the strings of the translation passing the key as an option" do
33
+ options = {key: "test_string"}
34
+
35
+ VCR.use_cassette "translation/fetch_with_details_and_key_strings" do
36
+ expect(resource.translation("en").strings.fetch_with_details(options)).to eq language_strings_with_details
37
+ end
38
+ end
39
+
40
+ it "returns an empty hash if the specified context doesn't exist" do
41
+ options = {context: "non_existing_context"}
42
+
43
+ VCR.use_cassette "translation/fetch_with_details_and_context_strings" do
44
+ expect(resource.translation("en").strings.fetch(options)).to eq []
45
+ end
42
46
  end
43
47
  end
44
48
 
45
49
  describe "Update" do
46
- it "should raise an error if the key parameter is not provided" do
47
- expect{ @resource.translation('fr').strings.update({:translation => "lol"}) }.to raise_error(Transifex::MissingParametersError)
50
+ it "should raise an error if the key is not provided" do
51
+ VCR.use_cassette "translation/update_without_key_string" do
52
+ expect { resource.translation("en").strings.update(translation: "no key") }
53
+ .to raise_error(Transifex::MissingParametersError)
54
+ .with_message("The following attributes are missing: key")
55
+ end
48
56
  end
49
- it "should not raise an error and update the specified translation string" do
50
- expect{ @resource.translation('fr').strings.update({:key => "routes.mercury_editor", :translation => "lol"}) }.to_not raise_error
57
+
58
+ it "updates the translation string for the resource for a certain language" do
59
+ params = {key: "test_string", translation: "updated translation"}
60
+
61
+ VCR.use_cassette "translation/update_single_translation_strings" do
62
+ expect(resource.translation("en").strings.update(params)).to eq "OK"
63
+ expect(resource.translation("en").string(params[:key]).fetch["translation"]).to eq params[:translation]
64
+ end
51
65
  end
52
- it "should not raise an error and update multiple translation strings" do
53
- params = [{:key => "routes.mercury_editor", :context => "", :translation => "lol"}, {:key => "date.abbr_day_names", :translation => "lol"}]
54
- expect{ @resource.translation('fr').strings.update(params) }.to_not raise_error
66
+
67
+ it "updates multiple translation strings" do
68
+ params = [
69
+ {key: "test_string", translation: "multiple translations"},
70
+ {key: "yet_another_string", translation: "yet another translation"}
71
+ ]
72
+
73
+ VCR.use_cassette "translation/update_multiple_translation_strings" do
74
+ expect(resource.translation("en").strings.update(params)).to eq "OK"
75
+ expect(resource.translation("en").strings.fetch).to eq multiple_language_strings
76
+ end
55
77
  end
56
78
  end
57
- end
79
+ end