pincerna 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +77 -0
  4. data/.travis-gemfile +17 -0
  5. data/.travis.yml +7 -0
  6. data/.yardopts +1 -0
  7. data/CHANGELOG.md +3 -0
  8. data/Gemfile +23 -0
  9. data/LICENSE.md +21 -0
  10. data/README.md +211 -0
  11. data/Rakefile +45 -0
  12. data/bin/pincernad +56 -0
  13. data/docs/Pincerna.html +130 -0
  14. data/docs/Pincerna/Base.html +3051 -0
  15. data/docs/Pincerna/Bookmark.html +523 -0
  16. data/docs/Pincerna/Cache.html +767 -0
  17. data/docs/Pincerna/ChromeBookmark.html +308 -0
  18. data/docs/Pincerna/CurrencyConversion.html +589 -0
  19. data/docs/Pincerna/FirefoxBookmark.html +328 -0
  20. data/docs/Pincerna/Ip.html +1017 -0
  21. data/docs/Pincerna/Map.html +399 -0
  22. data/docs/Pincerna/SafariBookmark.html +308 -0
  23. data/docs/Pincerna/Server.html +673 -0
  24. data/docs/Pincerna/Translation.html +517 -0
  25. data/docs/Pincerna/UnitConversion.html +1042 -0
  26. data/docs/Pincerna/Version.html +189 -0
  27. data/docs/Pincerna/Vpn.html +561 -0
  28. data/docs/Pincerna/Weather.html +837 -0
  29. data/docs/_index.html +298 -0
  30. data/docs/class_list.html +54 -0
  31. data/docs/css/common.css +1 -0
  32. data/docs/css/full_list.css +57 -0
  33. data/docs/css/style.css +338 -0
  34. data/docs/file.README.html +327 -0
  35. data/docs/file_list.html +56 -0
  36. data/docs/frames.html +28 -0
  37. data/docs/index.html +327 -0
  38. data/docs/js/app.js +214 -0
  39. data/docs/js/full_list.js +178 -0
  40. data/docs/js/jquery.js +4 -0
  41. data/docs/method_list.html +389 -0
  42. data/docs/top-level-namespace.html +112 -0
  43. data/icon.png +0 -0
  44. data/images/chrome.png +0 -0
  45. data/images/currency.png +0 -0
  46. data/images/firefox.png +0 -0
  47. data/images/map.png +0 -0
  48. data/images/network.png +0 -0
  49. data/images/safari.png +0 -0
  50. data/images/translate.png +0 -0
  51. data/images/unit.png +0 -0
  52. data/images/vpn.png +0 -0
  53. data/images/weather.png +0 -0
  54. data/info.plist +961 -0
  55. data/it.cowtech.pincernad.plist +19 -0
  56. data/lib/pincerna.rb +30 -0
  57. data/lib/pincerna/base.rb +258 -0
  58. data/lib/pincerna/bookmark.rb +80 -0
  59. data/lib/pincerna/cache.rb +61 -0
  60. data/lib/pincerna/chrome_bookmark.rb +40 -0
  61. data/lib/pincerna/currency_conversion.rb +134 -0
  62. data/lib/pincerna/firefox_bookmark.rb +92 -0
  63. data/lib/pincerna/ip.rb +135 -0
  64. data/lib/pincerna/map.rb +30 -0
  65. data/lib/pincerna/safari_bookmark.rb +40 -0
  66. data/lib/pincerna/server.rb +85 -0
  67. data/lib/pincerna/translation.rb +67 -0
  68. data/lib/pincerna/unit_conversion.rb +120 -0
  69. data/lib/pincerna/version.rb +24 -0
  70. data/lib/pincerna/vpn.rb +74 -0
  71. data/lib/pincerna/weather.rb +188 -0
  72. data/pincerna.alfredworkflow +0 -0
  73. data/pincerna.gemspec +36 -0
  74. data/pincerna.sh +9 -0
  75. data/spec/cassettes/Pincerna_CurrencyConversion/_perform_filtering/should_return_valid_values.yml +38 -0
  76. data/spec/cassettes/Pincerna_Ip/_get_local_addresses/should_return_a_list_of_addresses.yml +47 -0
  77. data/spec/cassettes/Pincerna_Ip/_get_public_address/should_return_public_IP_address.yml +44 -0
  78. data/spec/cassettes/Pincerna_Translation/_perform_filtering/should_default_from_English_to_the_given_language_when_only_one_is_present.yml +124 -0
  79. data/spec/cassettes/Pincerna_Translation/_perform_filtering/should_query_Google_Translate_for_sentences_returning_no_alternatives.yml +51 -0
  80. data/spec/cassettes/Pincerna_Translation/_perform_filtering/should_query_Google_Translate_for_single_words.yml +71 -0
  81. data/spec/cassettes/Pincerna_Weather/_get_forecast/should_append_name.yml +177 -0
  82. data/spec/cassettes/Pincerna_Weather/_get_forecast/should_get_correct_forecasts.yml +339 -0
  83. data/spec/cassettes/Pincerna_Weather/_lookup_places/should_return_an_existing_WOEID_without_making_any_request.yml +56 -0
  84. data/spec/cassettes/Pincerna_Weather/_lookup_places/should_search_for_places.yml +189 -0
  85. data/spec/cassettes/Pincerna_Weather/_perform_filtering/should_get_forecast.yml +56 -0
  86. data/spec/coverage_helper.rb +44 -0
  87. data/spec/pincerna/base_spec.rb +166 -0
  88. data/spec/pincerna/bookmark_spec.rb +65 -0
  89. data/spec/pincerna/cache_spec.rb +88 -0
  90. data/spec/pincerna/chrome_bookmark_spec.rb +114 -0
  91. data/spec/pincerna/currency_conversion_spec.rb +46 -0
  92. data/spec/pincerna/firefox_bookmark_spec.rb +46 -0
  93. data/spec/pincerna/ip_spec.rb +194 -0
  94. data/spec/pincerna/map_spec.rb +24 -0
  95. data/spec/pincerna/safari_bookmark_spec.rb +237 -0
  96. data/spec/pincerna/server_spec.rb +108 -0
  97. data/spec/pincerna/translation_spec.rb +55 -0
  98. data/spec/pincerna/unit_conversion_spec.rb +98 -0
  99. data/spec/pincerna/vpn_spec.rb +68 -0
  100. data/spec/pincerna/weather_spec.rb +131 -0
  101. data/spec/spec_helper.rb +48 -0
  102. metadata +283 -0
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://where.yahooapis.com/v1/places.q(QUERY);count=5?appid=dj0yJmk9ZUpBZk1hQTJGRHM5JmQ9WVdrOVlUSnBjMGhUTjJVbWNHbzlOemsyTURNeU5EWXkmcz1jb25zdW1lcnNlY3JldCZ4PWRi&format=json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Origin:
22
+ - '*'
23
+ Cache-Control:
24
+ - public, must-revalidate
25
+ Connection:
26
+ - Keep-Alive
27
+ Content-Encoding:
28
+ - gzip
29
+ Content-Language:
30
+ - en-US
31
+ Content-Type:
32
+ - application/json; charset=UTF-8
33
+ Date:
34
+ - Wed, 07 Aug 2013 16:16:16 GMT
35
+ P3p:
36
+ - policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV
37
+ TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY
38
+ ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
39
+ Server:
40
+ - HTTP/1.1 UserFiberFramework/1.0
41
+ Transfer-Encoding:
42
+ - chunked
43
+ Vary:
44
+ - Accept-Encoding
45
+ Via:
46
+ - HTTP/1.1 r08.ycpi.gq1.yahoo.net UserFiberFramework/1.0
47
+ X-Yahoo-Serving-Host:
48
+ - wws3.geotech.gq1.yahoo.com
49
+ body:
50
+ encoding: ASCII-8BIT
51
+ string: !binary |-
52
+ H4sIAAAAAAAAA6pWKshJTE4tVrKqViouSSwqUbIy0FFKzi/Ng7BK8ksSc4Cs
53
+ 2loAAAAA//8DAACYu9cqAAAA
54
+ http_version:
55
+ recorded_at: Wed, 07 Aug 2013 16:16:16 GMT
56
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.
5
+ #
6
+
7
+ require "pathname"
8
+ require "simplecov"
9
+ require "coveralls"
10
+ require "json"
11
+
12
+ Coveralls.wear! if ENV["CI"] || ENV["JENKINS_URL"] # Do not load outside Travis
13
+
14
+ SimpleCov.start do
15
+ root = Pathname.new(File.dirname(__FILE__)) + ".."
16
+
17
+ add_filter do |src_file|
18
+ path = Pathname.new(src_file.filename).relative_path_from(root).to_s
19
+ path !~ /^lib/
20
+ end
21
+ end
22
+
23
+ # Backport this to fix an issue with ruby-units (https://github.com/colszowka/simplecov/pull/175).
24
+ # Remove once Simplecov reaches v-0.8.0.
25
+ class SimpleCov::FileList < Array
26
+ def covered_strength
27
+ return 0 if empty? or lines_of_code == 0
28
+ map {|f| f.covered_strength }.reduce(&:+).to_f / size
29
+ end
30
+ end
31
+
32
+ class SimpleCov::SourceFile
33
+ def covered_percent
34
+ return 100.0 if lines.length == 0 or lines.length == never_lines.count
35
+ relevant_lines = lines.count - never_lines.count - skipped_lines.count
36
+ if relevant_lines == 0
37
+ 0
38
+ else
39
+ (covered_lines.count) * 100.0 / relevant_lines.to_f
40
+ end
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,166 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.
5
+ #
6
+
7
+ require "spec_helper"
8
+ require "yaml"
9
+
10
+ describe Pincerna::Base do
11
+ subject { Pincerna::Base.new("QUERY", "yml") }
12
+
13
+ let(:reference_xml) {
14
+ <<EOXML
15
+ <?xml version="1.0"?>
16
+ <items>
17
+ <item first="FIRST" second="SECOND" third="THIRD">
18
+ <title>TITLE 1</title>
19
+ <subtitle>SUBTITLE 1</subtitle>
20
+ <icon>ICON 1</icon>
21
+ </item>
22
+ <item fourth="FOURTH" fifth="FIFTH" sixth="SIXTH">
23
+ <title>TITLE 2</title>
24
+ <subtitle>SUBTITLE 2</subtitle>
25
+ <icon>ICON 2</icon>
26
+ </item>
27
+ </items>
28
+ EOXML
29
+
30
+ }
31
+ describe ".execute" do
32
+ it "should find relevant class" do
33
+ expect(Pincerna::Map).to receive(:new).and_call_original
34
+ expect(Pincerna::Base.execute!("map", "QUERY"))
35
+ end
36
+
37
+ it "should create a query and then filter" do
38
+ query = ::Object.new
39
+ expect(query).to receive(:filter).and_return("FILTER")
40
+ expect(Pincerna::Map).to receive(:new).with("QUERY", "FORMAT", "DEBUG").and_return(query)
41
+ expect(Pincerna::Base.execute!("map", "QUERY", "FORMAT", "DEBUG"))
42
+ end
43
+
44
+ it "should not fail if a matching class is not found" do
45
+ expect { expect(Pincerna::Base.execute!("invalid", "QUERY")) }.not_to raise_error
46
+ end
47
+ end
48
+
49
+ describe "#initalize" do
50
+ it "should initialize correct attributes" do
51
+ expect(subject.instance_variable_get(:@query)).to eq("QUERY")
52
+ expect(subject.instance_variable_get(:@cache_dir)).to eq(::File.expand_path("~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/it.cowtech.pincerna"))
53
+ expect(subject.instance_variable_get(:@feedback_items)).to eq([])
54
+ expect(subject.format).to eq(:yml)
55
+
56
+ end
57
+
58
+ it "should save debug mode" do
59
+ reference = Pincerna::Base.new("QUERY", "yml", "DEBUG")
60
+ expect(reference.instance_variable_get(:@debug)).to eq("DEBUG")
61
+ end
62
+
63
+ it "should save format" do
64
+ reference = Pincerna::Base.new("QUERY", "yml", "DEBUG")
65
+ expect(reference.format).to eq(:yml)
66
+ expect(reference.format_content_type).to eq("text/x-yaml")
67
+
68
+ reference = Pincerna::Base.new("QUERY", "yaml", "DEBUG")
69
+ expect(reference.format).to eq(:yml)
70
+ expect(reference.format_content_type).to eq("text/x-yaml")
71
+
72
+ reference = Pincerna::Base.new("QUERY", "FOO", "DEBUG")
73
+ expect(reference.format).to eq(:xml)
74
+ expect(reference.format_content_type).to eq("text/xml")
75
+ end
76
+ end
77
+
78
+ describe "#filter" do
79
+ before(:each) do
80
+ allow(subject).to receive(:perform_filtering).with("QUERY").and_return([{query: "query"}])
81
+ allow(subject).to receive(:process_results).with([{query: "query"}]).and_return([{title: "QUERY", arg: "query"}])
82
+ end
83
+
84
+ it "match the query, filter it and then process" do
85
+ expect(subject.filter).to eq_as_yaml([{title: "QUERY", arg: "query"}])
86
+ end
87
+
88
+ it "should return an array if a failure occurs" do
89
+ allow(subject).to receive(:perform_filtering).and_raise(::ArgumentError)
90
+ allow(subject).to receive(:process_results).with([]).and_return([])
91
+ expect(subject.filter).to eq_as_yaml([])
92
+ end
93
+ end
94
+
95
+ describe "#perform_filtering" do
96
+ it "should abort with a warning" do
97
+ expect { subject.perform_filtering([]) }.to raise_error(::ArgumentError)
98
+ end
99
+ end
100
+
101
+ describe "#process_results" do
102
+ it "should abort with a warning" do
103
+ expect { subject.process_results([]) }.to raise_error(::ArgumentError)
104
+ end
105
+ end
106
+
107
+ describe "#add_feedback_item" do
108
+ before(:each) do
109
+ subject.add_feedback_item("ITEM 1")
110
+ subject.add_feedback_item("ITEM 2")
111
+ end
112
+
113
+ it "should append to the internal items list" do
114
+ expect(subject.instance_variable_get(:@feedback_items)).to eq(["ITEM 1", "ITEM 2"])
115
+ end
116
+ end
117
+
118
+ describe "#output_feedback" do
119
+ describe "when not in debug" do
120
+ before(:each) do
121
+ subject.add_feedback_item({title: "TITLE 1", subtitle: "SUBTITLE 1", icon: "ICON 1", first: "FIRST", second: "SECOND", third: "THIRD"})
122
+ subject.add_feedback_item({title: "TITLE 2", subtitle: "SUBTITLE 2", icon: "ICON 2", fourth: "FOURTH", fifth: "FIFTH", sixth: "SIXTH"})
123
+ allow(subject).to receive(:format).and_return(:xml)
124
+ allow(subject).to receive(:debug_mode).and_return(nil)
125
+ end
126
+
127
+ it "should return items as XML" do
128
+ expect(subject.output_feedback.gsub(/\s/, "")).to eq(reference_xml.gsub(/\s/, ""))
129
+ end
130
+ end
131
+
132
+ describe "when in debug" do
133
+ before(:each) do
134
+ subject.add_feedback_item("ITEM 1")
135
+ subject.add_feedback_item("ITEM 2")
136
+ end
137
+
138
+ it "should return items as YAML" do
139
+ expect(subject.output_feedback).to eq_as_yaml(["ITEM 1", "ITEM 2"])
140
+ end
141
+ end
142
+ end
143
+
144
+ describe "#round_float" do
145
+ it "should round a float to a certain precision" do
146
+ expect(subject.round_float(1)).to eq(1.000)
147
+ expect(subject.round_float(123.4567)).to eq(123.457)
148
+ expect(subject.round_float(123.456781, 5)).to eq(123.45678)
149
+ end
150
+ end
151
+
152
+ describe "#format_float" do
153
+ it "should format a float to a certain precision" do
154
+ expect(subject.format_float(1)).to eq("1")
155
+ expect(subject.format_float(123.45, 5)).to eq("123.45")
156
+ expect(subject.format_float(123.4567)).to eq("123.457")
157
+ expect(subject.format_float(123.456781, 5)).to eq("123.45678")
158
+ end
159
+ end
160
+
161
+ describe "#execute_command" do
162
+ it "should return the output of a command" do
163
+ expect(subject.send(:execute_command, "date", "+%s")).to match(/\d+/)
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Pincerna::Bookmark do
10
+ subject { Pincerna::Bookmark.new("QUERY", "yml") }
11
+
12
+ describe "#perform_filtering" do
13
+ before(:each) do
14
+ cache = Object.new
15
+ allow(cache).to receive(:use).and_yield
16
+ allow(Pincerna::Cache).to receive(:instance).and_return(cache)
17
+
18
+ allow(subject).to receive(:read_bookmarks) {
19
+ subject.instance_variable_set(:@bookmarks, [
20
+ {name: "NAME 1", url: "URL 1", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
21
+ {name: "2", url: "2", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
22
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1"},
23
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Altri Preferiti"}
24
+ ])
25
+ }
26
+ end
27
+
28
+ it "should call #read_bookmarks" do
29
+ expect(subject).to receive(:read_bookmarks)
30
+ subject.perform_filtering("1")
31
+ end
32
+
33
+ it "should filter by query and sort correctly" do
34
+ expect(subject.perform_filtering("")).to eq([
35
+ {name: "2", url: "2", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
36
+ {name: "NAME 1", url: "URL 1", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
37
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Altri Preferiti"},
38
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1"}
39
+ ])
40
+
41
+ expect(subject.perform_filtering("NAME")).to eq([
42
+ {name: "NAME 1", url: "URL 1", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
43
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Altri Preferiti"},
44
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1"}
45
+ ])
46
+
47
+ expect(subject.perform_filtering("2")).to eq([{name: "2", url: "2", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"}])
48
+
49
+ expect(subject.perform_filtering("3")).to eq([])
50
+ end
51
+ end
52
+
53
+ describe "#read_bookmarks" do
54
+ it "should abort with a warning" do
55
+ expect { subject.read_bookmarks }.to raise_error(::ArgumentError)
56
+ end
57
+ end
58
+
59
+ describe "#process_results" do
60
+ it "should correctly prepare results" do
61
+ expect(subject.process_results([{name: "TITLE", url: "URL"}])).to eq([{title: "TITLE", arg: "URL", subtitle: "Action this item to open the URL in the browser ...", icon: Pincerna::Bookmark::ICON}])
62
+ expect(subject.process_results([{name: "TITLE", url: "URL", path: "PATH"}])).to eq([{title: "TITLE", arg: "URL", subtitle: "PATH", icon: Pincerna::Bookmark::ICON}])
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Pincerna::Cache do
10
+ before(:each) do
11
+ Pincerna::Cache.instance_variable_set(:@instance, nil)
12
+ stub_const("Pincerna::Cache::FILE", "/tmp/pincerna-cache.db")
13
+ allow_any_instance_of(EventMachine::PeriodicTimer).to receive(:schedule)
14
+ end
15
+
16
+ after(:each) do
17
+ Pincerna::Cache.instance.destroy
18
+ FileUtils.rm_f(Pincerna::Cache::FILE)
19
+ end
20
+
21
+ describe ".instance" do
22
+ it "should return the instance" do
23
+ expect(Pincerna::Cache).to receive(:new).once.and_call_original
24
+ instance = Pincerna::Cache.instance
25
+ expect(instance).to be_a(Pincerna::Cache)
26
+ expect(instance).to be(Pincerna::Cache.instance)
27
+ end
28
+ end
29
+
30
+ describe "#initialize" do
31
+ it "should initialize variables" do
32
+ expect(Pincerna::Cache.instance.instance_variable_get(:@flusher)).to be_a(EventMachine::PeriodicTimer)
33
+ expect(Pincerna::Cache.instance.instance_variable_get(:@data)).to be_a(Daybreak::DB)
34
+ end
35
+ end
36
+
37
+ describe "#use" do
38
+ before(:each) do
39
+ allow(Time).to receive(:now).and_return(1000)
40
+ @control = ""
41
+ end
42
+
43
+ it "should read data from the store and not call the block, if present" do
44
+ Pincerna::Cache.instance.data["KEY"] = {expiration: Time.now.to_f + 1800, data: "1"}
45
+ expect(Pincerna::Cache.instance.use("KEY", 1800) { @control = "2" }).to eq("1")
46
+ expect(@control).to eq("")
47
+ end
48
+
49
+ it "should fetch new data if nothing is in cache, then save it back" do
50
+ Pincerna::Cache.instance.data["KEY"] = nil
51
+ expect(Pincerna::Cache.instance.use("KEY", 1800) { @control = "2" }).to eq("2")
52
+ expect(Pincerna::Cache.instance.data["KEY"]).to eq({data: "2", expiration: 2800})
53
+ expect(@control).to eq("2")
54
+ end
55
+
56
+ it "should fetch new data if the old one expired" do
57
+ Pincerna::Cache.instance.data["KEY"] = {expiration: 800, data: "1"}
58
+ expect(Pincerna::Cache.instance.use("KEY", 1800) { @control = "2" }).to eq("2")
59
+ expect(Pincerna::Cache.instance.data["KEY"]).to eq({data: "2", expiration: 2800})
60
+ expect(@control).to eq("2")
61
+ end
62
+ end
63
+
64
+ describe "#destroy" do
65
+ before(:each) do
66
+ flusher = Pincerna::Cache.instance.instance_variable_get(:@flusher)
67
+ data = Pincerna::Cache.instance.instance_variable_get(:@data)
68
+ expect(flusher).to receive(:cancel).twice
69
+ expect(data).to receive(:close).twice.and_call_original
70
+ end
71
+
72
+ it "should cancel the flusher and close the data" do
73
+ Pincerna::Cache.instance.destroy
74
+ end
75
+ end
76
+
77
+ describe "#flush" do
78
+ before(:each) do
79
+ data = Pincerna::Cache.instance.instance_variable_get(:@data)
80
+ expect(data).to receive(:flush)
81
+ expect(data).to receive(:compact)
82
+ end
83
+
84
+ it "should flush and compact data" do
85
+ Pincerna::Cache.instance.flush
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Pincerna::ChromeBookmark do
10
+ subject { Pincerna::ChromeBookmark.new("QUERY", "yml") }
11
+
12
+ describe "#Chrome_bookmarks" do
13
+ before(:each) do
14
+ @json = <<EOJSON
15
+ {
16
+ "checksum": "",
17
+ "roots": {
18
+ "bookmark_bar": {
19
+ "children": [
20
+ {
21
+ "children": [
22
+ {
23
+ "children": [
24
+ {
25
+ "date_added": "13018920348983801",
26
+ "id": "1145",
27
+ "name": "NAME 1",
28
+ "type": "url",
29
+ "url": "URL 1"
30
+ },
31
+ {
32
+ "date_added": "13018920348983801",
33
+ "id": "1145",
34
+ "name": "NAME 2",
35
+ "type": "url",
36
+ "url": "URL 2"
37
+ }
38
+ ],
39
+ "date_added": "13018920348874387",
40
+ "date_modified": "13018920348996854",
41
+ "id": "1087",
42
+ "name": "FOLDER 2",
43
+ "type": "folder"
44
+ },
45
+ {
46
+ "date_added": "13018920348983801",
47
+ "id": "1145",
48
+ "name": "NAME 3",
49
+ "type": "url",
50
+ "url": "URL 3"
51
+ }
52
+ ],
53
+ "date_added": "13018920348873174",
54
+ "date_modified": "13018920348989347",
55
+ "id": "1086",
56
+ "name": "FOLDER 1",
57
+ "type": "folder"
58
+ }
59
+ ],
60
+ "date_added": "12980910274469592",
61
+ "date_modified": "13005935882687426",
62
+ "id": "1",
63
+ "name": "Barra dei Preferiti",
64
+ "type": "folder"
65
+ },
66
+ "other": {
67
+ "children": [
68
+ {
69
+ "date_added": "13018920348983801",
70
+ "id": "1145",
71
+ "name": "NAME 4",
72
+ "type": "url",
73
+ "url": "URL 4"
74
+ }
75
+ ],
76
+ "date_added": "12980910274469613",
77
+ "date_modified": "13020577556062605",
78
+ "id": "2",
79
+ "name": "Altri Preferiti",
80
+ "type": "folder"
81
+ },
82
+ "synced": {
83
+ "children": [ ],
84
+ "date_added": "12980910274469615",
85
+ "date_modified": "0",
86
+ "id": "3",
87
+ "name": "Preferiti su disp. mobili",
88
+ "type": "folder"
89
+ }
90
+ },
91
+ "version": 1
92
+ }
93
+ EOJSON
94
+ end
95
+
96
+ it "should read the JSON file to get latest bookmarks" do
97
+ expect(File).to receive(:read).with(File.expand_path("~/Library/Application Support/Google/Chrome/Default/Bookmarks")).and_return("{}")
98
+ expect(Oj).to receive(:load).with("{}").and_return({"roots" => {}})
99
+ subject.read_bookmarks
100
+ end
101
+
102
+ it "should return the correct list of bookmarks" do
103
+ expect(subject.instance_variable_set(:@bookmarks, []))
104
+ expect(File).to receive(:read).and_return(@json)
105
+ subject.read_bookmarks
106
+ expect(subject.instance_variable_get(:@bookmarks)).to eq([
107
+ {name: "NAME 1", url: "URL 1", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
108
+ {name: "NAME 2", url: "URL 2", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1 \u2192 FOLDER 2"},
109
+ {name: "NAME 3", url: "URL 3", path: " \u2192 Barra dei Preferiti \u2192 FOLDER 1"},
110
+ {name: "NAME 4", url: "URL 4", path: " \u2192 Altri Preferiti"}
111
+ ])
112
+ end
113
+ end
114
+ end