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.
- checksums.yaml +6 -14
- data/.gitignore +17 -17
- data/.rspec +2 -0
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +517 -513
- data/Rakefile +1 -1
- data/lib/transifex.rb +84 -87
- data/lib/transifex/crud_requests.rb +43 -33
- data/lib/transifex/errors.rb +4 -4
- data/lib/transifex/project_components/language.rb +1 -1
- data/lib/transifex/project_components/language_components/coordinators.rb +4 -6
- data/lib/transifex/project_components/language_components/reviewers.rb +5 -8
- data/lib/transifex/project_components/language_components/translators.rb +6 -9
- data/lib/transifex/project_components/languages.rb +1 -1
- data/lib/transifex/resource.rb +1 -1
- data/lib/transifex/resource_components/content.rb +1 -1
- data/lib/transifex/resource_components/source.rb +1 -1
- data/lib/transifex/resource_components/stats.rb +1 -1
- data/lib/transifex/resource_components/translation.rb +1 -1
- data/lib/transifex/resource_components/translation_components/string.rb +1 -1
- data/lib/transifex/resource_components/translation_components/strings.rb +1 -1
- data/lib/transifex/resources.rb +1 -1
- data/lib/transifex/version.rb +3 -3
- data/spec/cassettes/fetch_formats.yml +121 -0
- data/spec/cassettes/language/fetch_language_info.yml +58 -0
- data/spec/cassettes/language/fetch_languages_info.yml +58 -0
- data/spec/cassettes/project/components/create_language.yml +95 -0
- data/spec/cassettes/project/components/create_language_non_existing_coordinator.yml +48 -0
- data/spec/cassettes/project/components/create_language_without_coordinator.yml +48 -0
- data/spec/cassettes/project/components/fetch_languages.yml +53 -0
- data/spec/cassettes/project/delete_project.yml +108 -0
- data/spec/cassettes/project/fetch_private_project_info.yml +59 -0
- data/spec/cassettes/project/fetch_with_details_private_project_info.yml +66 -0
- data/spec/cassettes/project/language/delete_language.yml +140 -0
- data/spec/cassettes/project/language/fetch_coordinators.yml +56 -0
- data/spec/cassettes/project/language/fetch_language_info.yml +52 -0
- data/spec/cassettes/project/language/fetch_reviewers.yml +56 -0
- data/spec/cassettes/project/language/fetch_translators.yml +54 -0
- data/spec/cassettes/project/language/fetch_with_details_language_info.yml +54 -0
- data/spec/cassettes/project/language/update_coordinators.yml +104 -0
- data/spec/cassettes/project/language/update_language.yml +100 -0
- data/spec/cassettes/project/language/update_non_existing_coordinator.yml +48 -0
- data/spec/cassettes/project/language/update_non_existing_language.yml +49 -0
- data/spec/cassettes/project/language/update_non_existing_reviewer.yml +101 -0
- data/spec/cassettes/project/language/update_non_existing_translator.yml +101 -0
- data/spec/cassettes/project/language/update_reviewers.yml +157 -0
- data/spec/cassettes/project/language/update_translators.yml +157 -0
- data/spec/cassettes/project/update_non_existing_attribute_private_project.yml +54 -0
- data/spec/cassettes/project/update_private_project.yml +120 -0
- data/spec/cassettes/project/update_with_missing_params_private_project.yml +54 -0
- data/spec/cassettes/projects/create_private_project.yml +111 -0
- data/spec/cassettes/projects/create_public_project.yml +111 -0
- data/spec/cassettes/projects/create_used_slug_project.yml +55 -0
- data/spec/cassettes/projects/fetch_projects.yml +61 -0
- data/spec/cassettes/resource/delete_not_existing_resource.yml +55 -0
- data/spec/cassettes/resource/delete_resource.yml +160 -0
- data/spec/cassettes/resource/fetch_all_languages_stats.yml +66 -0
- data/spec/cassettes/resource/fetch_content_as_file.yml +56 -0
- data/spec/cassettes/resource/fetch_content_as_hash.yml +58 -0
- data/spec/cassettes/resource/fetch_language_stats.yml +61 -0
- data/spec/cassettes/resource/fetch_not_existing_resource.yml +55 -0
- data/spec/cassettes/resource/fetch_resource_info.yml +59 -0
- data/spec/cassettes/resource/fetch_source_string_metadata.yml +52 -0
- data/spec/cassettes/resource/fetch_translations.yml +57 -0
- data/spec/cassettes/resource/fetch_updated_resource_info.yml +60 -0
- data/spec/cassettes/resource/fetch_updated_source_string_metadata.yml +52 -0
- data/spec/cassettes/resource/fetch_with_details_resource_info.yml +65 -0
- data/spec/cassettes/resource/fetch_with_file_and_mode_translations.yml +56 -0
- data/spec/cassettes/resource/fetch_with_file_translations.yml +56 -0
- data/spec/cassettes/resource/update_content_json.yml +115 -0
- data/spec/cassettes/resource/update_content_with_wrong_mimetype.yml +59 -0
- data/spec/cassettes/resource/update_content_yml.yml +114 -0
- data/spec/cassettes/resource/update_not_existing_resource.yml +55 -0
- data/spec/cassettes/resource/update_resource_info.yml +114 -0
- data/spec/cassettes/resource/update_source_language.yml +54 -0
- data/spec/cassettes/resource/update_source_string_metadata.yml +100 -0
- data/spec/cassettes/resource/update_translation_for_language.yml +62 -0
- data/spec/cassettes/resources/create_from_file.yml +55 -0
- data/spec/cassettes/resources/create_from_string.yml +54 -0
- data/spec/cassettes/resources/fetch_as_array.yml +62 -0
- data/spec/cassettes/resources/non_existing_project.yml +55 -0
- data/spec/cassettes/translation/fetch_string.yml +55 -0
- data/spec/cassettes/translation/fetch_strings.yml +54 -0
- data/spec/cassettes/translation/fetch_with_details_and_context_strings.yml +51 -0
- data/spec/cassettes/translation/fetch_with_details_and_key_strings.yml +56 -0
- data/spec/cassettes/translation/fetch_with_details_strings.yml +56 -0
- data/spec/cassettes/translation/update_multiple_translation_strings.yml +107 -0
- data/spec/cassettes/translation/update_single_translation_strings.yml +104 -0
- data/spec/cassettes/translation/update_string.yml +104 -0
- data/spec/lib/transifex/coordinators_spec.rb +22 -16
- data/spec/lib/transifex/formats_spec.rb +8 -8
- data/spec/lib/transifex/language_spec.rb +9 -10
- data/spec/lib/transifex/languages_spec.rb +8 -8
- data/spec/lib/transifex/project_language_spec.rb +41 -28
- data/spec/lib/transifex/project_languages_spec.rb +34 -18
- data/spec/lib/transifex/project_spec.rb +46 -73
- data/spec/lib/transifex/projects_spec.rb +72 -37
- data/spec/lib/transifex/resource_content_spec.rb +41 -24
- data/spec/lib/transifex/resource_source_spec.rb +21 -19
- data/spec/lib/transifex/resource_spec.rb +69 -41
- data/spec/lib/transifex/resources_spec.rb +42 -34
- data/spec/lib/transifex/reviewers_spec.rb +23 -17
- data/spec/lib/transifex/stats_spec.rb +20 -24
- data/spec/lib/transifex/translation_spec.rb +60 -38
- data/spec/lib/transifex/translation_string_spec.rb +26 -20
- data/spec/lib/transifex/translation_strings_spec.rb +65 -43
- data/spec/lib/transifex/translators_spec.rb +23 -17
- data/spec/lib/transifex_spec.rb +15 -0
- data/spec/lib/yaml/eo.yml +3 -0
- data/spec/spec_helper.rb +19 -83
- data/spec/support/client_helper.rb +8 -0
- data/spec/support/content_helper.rb +346 -0
- data/transifex-interface-ruby.gemspec +28 -25
- metadata +198 -21
- data/spec/lib/transifex/configuration_spec.rb +0 -17
- data/spec/lib/yaml/resource_translation_default_content_test.yml +0 -4
- data/spec/lib/yaml/resource_translation_reviewed_content_test.yml +0 -9
@@ -1,50 +1,58 @@
|
|
1
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
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{
|
34
|
-
|
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
|
41
|
-
|
42
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Transifex::ProjectComponents::LanguageComponents::Reviewers do
|
4
|
-
|
5
|
-
@project = Transifex::Project.new("projet-de-test-1")
|
6
|
-
end
|
4
|
+
let(:project) { Transifex::Project.new("ruby-client") }
|
7
5
|
|
8
|
-
describe "
|
9
|
-
it "should raise an error
|
10
|
-
expect{ Transifex::ProjectComponents::LanguageComponents::Reviewers.new }
|
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 "
|
16
|
-
|
17
|
-
|
18
|
-
|
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 "
|
25
|
-
|
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
|
29
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::Stats do
|
4
|
-
|
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 "
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::Translation do
|
4
|
-
|
5
|
-
|
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 "
|
10
|
-
it "should raise an error
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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 = {:
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::TranslationComponents::String do
|
4
|
-
|
5
|
-
|
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 "
|
10
|
-
it "should raise an error
|
11
|
-
expect{ Transifex::ResourceComponents::TranslationComponents::String.new }
|
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
|
17
|
-
expect{
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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 "
|
29
|
-
params = {:
|
30
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::TranslationComponents::Strings do
|
4
|
-
|
5
|
-
|
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 "
|
10
|
-
it "should raise an error
|
11
|
-
expect{ Transifex::ResourceComponents::TranslationComponents::Strings.new }
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
47
|
-
|
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
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|