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,91 +1,64 @@
|
|
1
|
-
|
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
|
-
|
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 "
|
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
|
-
|
20
|
-
describe "fetch" do
|
21
|
-
it "should retrieve
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
expect
|
60
|
-
expect(
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
expect {
|
74
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::Projects do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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 "
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::Content do
|
4
|
-
|
5
|
-
|
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 "
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
expect(
|
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 "
|
34
|
-
|
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
|
-
|
37
|
-
|
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
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Transifex::ResourceComponents::Source do
|
4
|
-
|
5
|
-
|
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 "
|
10
|
-
it "should raise an error
|
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
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
26
|
-
params = {:
|
27
|
-
|
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
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
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
|