one_sky 1.0.0 → 2.0.0

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.
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe OneSky::Platform do
4
+ let(:api_key) { "apikey" }
5
+ let(:secret) { "secret" }
6
+ let(:project_name) { "some-project" }
7
+ let(:platform_id) { 123 }
8
+
9
+ let(:client) { OneSky::Client.new(api_key, secret) }
10
+ let(:project) { client.project(project_name) }
11
+ let(:platform) { project.platform(platform_id) }
12
+
13
+ describe "proxies" do
14
+
15
+ describe "translation" do
16
+
17
+ let(:translation) { platform.translation }
18
+
19
+ it "returns a OneSky::Translation instance" do
20
+ translation.should be_an_instance_of OneSky::Translation
21
+ end
22
+
23
+ it "sets the client to itself" do
24
+ translation.client.should == client
25
+ end
26
+
27
+ it "sets the same platform_id" do
28
+ translation.platform_id.should == platform_id
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ describe "details" do
35
+
36
+ let(:example) do
37
+ # example from the api docs
38
+ # but with the outer key as "platform" (the docs say "project")
39
+ {
40
+ "platform" => {
41
+ "name" => "Website",
42
+ "base_locale" => "en_US",
43
+ "type" => {
44
+ "name" => "iPhone/iPad App",
45
+ "code" => "ios"
46
+ }
47
+ }
48
+ }
49
+ end
50
+
51
+ it "calls /platform/details" do
52
+ # example from the api docs
53
+ # but with the outer key as "platform" (the docs say "project")
54
+ client.should_receive(:get).with("platform/details", :"platform-id" => platform_id).and_return(example)
55
+ platform.details.should == example["platform"]
56
+ end
57
+ end
58
+
59
+ describe "locales" do
60
+
61
+ let(:example) do
62
+ {
63
+ "locales" => [
64
+ {
65
+ "locale" => "en_US",
66
+ "name" => {
67
+ "eng" => "English (US)",
68
+ "local" => "English (US)"
69
+ },
70
+ "locale_ios" => "en",
71
+ "is_active" => true,
72
+ "is_private" => false,
73
+ "string_select_threshold" => 3,
74
+ "string_confirm_threshold" => 20,
75
+ "completeness" => 0,
76
+ },
77
+ {
78
+ "locale" => "zh_TW",
79
+ "name" => {
80
+ "eng" => "Traditional Chinese",
81
+ "local" => "*some-chinese*"
82
+ },
83
+ "locale_ios" => "zh-Hant",
84
+ "is_active" => true,
85
+ "is_private" => false,
86
+ "string_select_threshold" => 3,
87
+ "string_confirm_threshold" => 20,
88
+ "completeness" => 0,
89
+ },
90
+ ]
91
+ }
92
+ end
93
+
94
+ it "calls /platform/locales" do
95
+ # examples from the api docs
96
+ client.should_receive(:get).with("platform/locales", :"platform-id" => platform_id).and_return(example)
97
+ platform.locales.should == example["locales"]
98
+ end
99
+ end
100
+
101
+ end
data/spec/project_spec.rb CHANGED
@@ -1,58 +1,77 @@
1
- require 'helpers'
1
+ require 'spec_helper'
2
2
 
3
- describe "Project" do
4
- include OneSkySpecHelpers
5
-
6
- it "raises an error when initialization values are nil." do
7
- lambda { @project = OneSky::Project.new(nil, nil, nil) }.should raise_error ArgumentError
8
- end
9
- end
10
-
11
- describe "Project" do
12
- include OneSkySpecHelpers
13
-
14
- before do
15
- @project = create_project
16
- end
17
-
18
- it "raises an error when incorrect API credentials are passed." do
19
- @project.api_secret = "wrong secret"
20
- lambda { @project.details }.should raise_error RestClient::Exception
21
- end
22
-
23
- describe "#details" do
24
- it "returns project name among other things." do
25
- @project.details["name"].should == @project.name
3
+ describe OneSky::Project do
4
+ let(:api_key) { "apikey" }
5
+ let(:secret) { "secret" }
6
+ let(:project_name) { "some-project" }
7
+
8
+ let(:client) { OneSky::Client.new(api_key, secret) }
9
+ let(:project) { client.project(project_name) }
10
+
11
+ describe "proxies" do
12
+
13
+ describe "platform" do
14
+
15
+ let(:platform_id) { 123 }
16
+ let(:platform) { project.platform(platform_id) }
17
+
18
+ it "returns a OneSky::Platform instance" do
19
+ platform.should be_an_instance_of OneSky::Platform
20
+ end
21
+
22
+ it "sets the client to itself" do
23
+ platform.client.should == client
24
+ end
25
+
26
+ it "sets the provided platform_id" do
27
+ platform.platform_id.should == platform_id
28
+ end
26
29
  end
30
+
27
31
  end
28
-
29
- describe "#types" do
30
- it "returns an array." do
31
- types = @project.types
32
- types.should be_an(Array)
33
- types.size.should > 0
32
+
33
+ describe "platforms" do
34
+
35
+ let(:example) do
36
+ {
37
+ "platforms" => [
38
+ {
39
+ "id" => 1,
40
+ "type" => "iPhone/iPad App",
41
+ "code" => "ios"
42
+ },
43
+ {
44
+ "id" => 2,
45
+ "type" => "Miscelleneous",
46
+ "code" => "misc",
47
+ "description" => "database"
48
+ }
49
+ ]
50
+ }
34
51
  end
35
- end
36
-
37
- describe "#languages" do
38
- it "returns an array." do
39
- langs = @project.languages
40
- langs.should be_an(Array)
41
- langs.size.should > 0
52
+
53
+ it "calls /project/platforms" do
54
+ # examples from the api docs
55
+ client.should_receive(:get).with("project/platforms", :project => project_name).and_return(example)
56
+ project.platforms.should == example["platforms"]
42
57
  end
43
58
  end
44
-
45
- describe "#info" do
46
- it "returns a hash." do
47
- info = @project.info
48
- info.should be_an(Hash)
49
- info.has_key?("name").should be_true
59
+
60
+ describe "details" do
61
+
62
+ let(:example) do
63
+ {
64
+ "project" => {
65
+ "name" => "Website",
66
+ "base_locale" => "en_US"
67
+ }
68
+ }
50
69
  end
51
- end
52
-
53
- describe "#get_sso_link" do
54
- it "returns a URL string." do
55
- @project.get_sso_link("rspec_process").should match /^http.*$/
70
+
71
+ it "calls /project/details" do
72
+ client.should_receive(:get).with("project/details", :project => project_name).and_return(example)
73
+ project.details.should == example["project"]
56
74
  end
57
75
  end
76
+
58
77
  end
@@ -1,7 +1,7 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
1
+ $:.unshift File.expand_path(File.dirname(__FILE__)+'/../lib')
3
2
 
4
3
  require 'one_sky'
4
+ require 'time_freeze'
5
5
 
6
6
  module OneSkySpecHelpers
7
7
  def create_project
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe OneSky::Translation do
4
+ let(:api_key) { "apikey" }
5
+ let(:secret) { "secret" }
6
+ let(:project_name) { "some-project" }
7
+ let(:platform_id) { 123 }
8
+
9
+ let(:client) { OneSky::Client.new(api_key, secret) }
10
+ let(:project) { client.project(project_name) }
11
+ let(:platform) { project.platform(platform_id) }
12
+ let(:translation) { platform.translation }
13
+
14
+ describe "input_strings" do
15
+
16
+ let(:string_array) {
17
+ ["test1", "test2"]
18
+ }
19
+
20
+ let(:hash_array) {
21
+ [{:string => "test1"}, {:string => "test2"}]
22
+ }
23
+
24
+ context "with an array of strings" do
25
+ it "calls /string/input" do
26
+ client.should_receive(:post).with("string/input", :input => JSON.dump(hash_array), :"platform-id" => platform_id)
27
+
28
+ translation.input_strings(string_array)
29
+ end
30
+ end
31
+
32
+ context "with an array of hashes" do
33
+ it "calls /string/input" do
34
+ client.should_receive(:post).with("string/input", :input => JSON.dump(hash_array), :"platform-id" => platform_id)
35
+
36
+ translation.input_strings(hash_array)
37
+ end
38
+ end
39
+
40
+ context "with a complex array of hashes" do
41
+ it "dasherizes the keys" do
42
+ original = [{:string => "Test 1", :string_key => "test1"}]
43
+ dasherized = [{:string => "Test 1", :"string-key" => "test1"}]
44
+
45
+ client.should_receive(:post).with("string/input", :input => JSON.dump(dasherized), :"platform-id" => platform_id)
46
+
47
+ translation.input_strings(original)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "input_string" do
53
+ it "defers to input_strings" do
54
+ translation.should_receive(:input_strings).with(["test1"])
55
+ translation.input_string("test1")
56
+ end
57
+ end
58
+
59
+ describe "input_phrases" do
60
+ it "defers to input_strings" do
61
+ translation.should_receive(:input_strings).with([{:string_key => "test1", :string => "Test 1"}])
62
+ translation.input_phrases("test1" => "Test 1")
63
+ end
64
+ end
65
+
66
+ describe "translate" do
67
+
68
+ let(:string_key) { "test1" }
69
+ let(:locale) { "en_US" }
70
+ let(:string) { "Test 1" }
71
+
72
+ it "calls /string/translate" do
73
+ client.should_receive(:post).with(
74
+ "string/translate",
75
+ :"string-key" => string_key,
76
+ :locale => locale,
77
+ :translation => string,
78
+ :"platform-id" => platform_id
79
+ )
80
+
81
+ translation.translate(string_key, locale, string)
82
+ end
83
+ end
84
+
85
+ describe "output" do
86
+
87
+ let(:example) do
88
+ {
89
+ "translation" => {
90
+ "Tag A" => {
91
+ "Locale A" => {
92
+ "String Key A" => "string",
93
+ "String Key B" => {
94
+ "Context A" => "string",
95
+ "Context B" => "string"
96
+ }
97
+ },
98
+ "Locale B" => {
99
+ "String Key A" => "string"
100
+ }
101
+ },
102
+ "Tag B" => {
103
+ "Locale A" => {
104
+ "String Key C" => "string"
105
+ }
106
+ }
107
+ },
108
+ "md5" => "95e6198f16ea363291dfa9bc18282545"
109
+ }
110
+ end
111
+
112
+ it "calls /string/output" do
113
+ client.should_receive(:get).with("string/output", :"platform-id" => platform_id).and_return(example)
114
+ translation.output.should == example["translation"]
115
+ end
116
+
117
+ context "for_locale" do
118
+ it "calls /string/output with the locale" do
119
+ client.should_receive(:get).with("string/output", :"platform-id" => platform_id, :locale => "en_US").and_return(example)
120
+ translation.output_for_locale("en_US").should == example["translation"]
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe OneSky::Utility do
4
+ let(:api_key) { "apikey" }
5
+ let(:secret) { "secret" }
6
+
7
+ let(:client) { OneSky::Client.new(api_key, secret) }
8
+ let(:utility) { client.utility }
9
+
10
+
11
+ describe "locales" do
12
+
13
+ let(:example) do
14
+ # example from the api docs
15
+ {
16
+ "locales" => [
17
+ {
18
+ "locale" => "en_US",
19
+ "name" => {
20
+ "eng" => "English (US)",
21
+ "local" => "English (US)"
22
+ },
23
+ "locale_ios" => "en"
24
+ },
25
+ {
26
+ "locale" => "af_ZA",
27
+ "name" => {
28
+ "eng" => "Afrikaans",
29
+ "local" => "Afrikaans"
30
+ }
31
+ },
32
+ {
33
+ "locale" => "sq_AL",
34
+ "name" => {
35
+ "eng" => "Albanian",
36
+ "local" => "Shqip"
37
+ }
38
+ }
39
+ ]
40
+ }
41
+ end
42
+
43
+ it "calls /locales" do
44
+ client.should_receive(:get).with("locales").and_return(example)
45
+ utility.locales.should == example["locales"]
46
+ end
47
+ end
48
+
49
+ describe "platform_types" do
50
+
51
+ let(:example) do
52
+ {
53
+ "types" => [
54
+ {
55
+ "name" => "iPhone/iPad App",
56
+ "code" => "ios"
57
+ },
58
+ {
59
+ "name" => "Android App",
60
+ "code" => "android"
61
+ },
62
+ {
63
+ "name" => "Website",
64
+ "code" => "website"
65
+ },
66
+ {
67
+ "name" => "Miscellaneous",
68
+ "code" => "misc"
69
+ }
70
+ ]
71
+ }
72
+ end
73
+
74
+ it "calls /platform-types" do
75
+ client.should_receive(:get).with("platform-types").and_return(example)
76
+ utility.platform_types.should == example["types"]
77
+ end
78
+ end
79
+
80
+ describe "get_sso_link" do
81
+
82
+ let(:unique_id) { "abc123" }
83
+ let(:name) { "fred" }
84
+
85
+ let(:example) do
86
+ {
87
+ "url" => "http:\/\/global.oneskyapp.com\/?time=1290495566&id=abc@oneskyapp.com&data=d98e3fc22ba4bce8537bfef7929f1fc5&name=Leon",
88
+ "md5" => "7f4d51e53b0e2fec49262840caa29720"
89
+ }
90
+ end
91
+
92
+ it "calls /sso/get-link" do
93
+ client.should_receive(:post).with("sso/get-link", :"unique-id" => unique_id, :name => name).and_return(example)
94
+ utility.get_sso_link(unique_id, name).should == example["url"]
95
+ end
96
+ end
97
+
98
+ end