gliffy 0.0.6

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,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gliffy::Document::PNG do
4
+ let(:content) { "SAMPLE CONTENT" }
5
+ let(:document) { double(Gliffy::Document) }
6
+ let(:png) { Gliffy::Document::PNG.new(document) }
7
+
8
+ it "has a reference to the original document" do
9
+ expect(png).to respond_to :document
10
+ expect(png.document).to be document
11
+ end
12
+
13
+ it "has content" do
14
+ expect(png).to respond_to :content
15
+ end
16
+
17
+ it "delegates task of fetching image content to the API facade" do
18
+ account = double(Gliffy::Account, :id => 11)
19
+ api = double(Gliffy::API)
20
+ document.stub(:api).and_return(api)
21
+ document.stub(:owner).and_return(account)
22
+ document.stub(:id).and_return(22)
23
+ api.should_receive(
24
+ :raw
25
+ ).with(
26
+ "/accounts/11/documents/22.png",
27
+ hash_including(
28
+ :action => "get",
29
+ :size => "T"
30
+ )
31
+ ).and_return(content)
32
+
33
+ expect(png.content(Gliffy::Document::PNG::SIZE_THUMBNAIL)).to eq content
34
+ end
35
+
36
+ it "has a thumbnail" do
37
+ png.stub(:content).and_return(content)
38
+ expect(png.thumbnail).to eq content
39
+ expect(png).to have_received(:content).with(
40
+ Gliffy::Document::PNG::SIZE_THUMBNAIL
41
+ )
42
+ end
43
+
44
+ it "has a small image" do
45
+ png.stub(:content).and_return(content)
46
+ expect(png.small).to eq content
47
+ expect(png).to have_received(:content).with(
48
+ Gliffy::Document::PNG::SIZE_SMALL
49
+ )
50
+ end
51
+
52
+ it "has a medium image" do
53
+ png.stub(:content).and_return(content)
54
+ expect(png.medium).to eq content
55
+ expect(png).to have_received(:content).with(
56
+ Gliffy::Document::PNG::SIZE_MEDIUM
57
+ )
58
+ end
59
+
60
+ it "has a full image" do
61
+ png.stub(:content).and_return(content)
62
+ expect(png.full).to eq content
63
+ expect(png).to have_received(:content).with(
64
+ Gliffy::Document::PNG::SIZE_FULL
65
+ )
66
+ end
67
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gliffy::Document do
4
+ before :each do
5
+ Gliffy::Document.clear_cache
6
+ end
7
+
8
+ let(:api) { double(Gliffy::API) }
9
+ let(:owner) do
10
+ owner = double(Gliffy::Account)
11
+ owner.stub(:api).and_return(api)
12
+ owner
13
+ end
14
+
15
+ let(:document_id) { 1000002 }
16
+ let(:document_name) { 'SNPP Domain Model' }
17
+
18
+ let(:response) do
19
+ Gliffy::API::Response.new(fixture(
20
+ "document",
21
+ :document_id => document_id,
22
+ :document_name => document_name
23
+ )
24
+ )
25
+ end
26
+
27
+ let(:document) do
28
+ Gliffy::Document.load(owner, response.node("//g:document"))
29
+ end
30
+
31
+ it "has an id" do
32
+ expect(document).to respond_to :id
33
+ expect(document.id).to eq document_id
34
+ end
35
+
36
+ it "has a name" do
37
+ expect(document).to respond_to :name
38
+ expect(document.name).to eq document_name
39
+ end
40
+
41
+ it "has 'public access' flag" do
42
+ expect(document).to respond_to :public?
43
+ expect(document.public?).to eq(true)
44
+ end
45
+
46
+ it "has a version number" do
47
+ expect(document).to respond_to :versions
48
+ expect(document.versions).to eq(5)
49
+ end
50
+
51
+ it "has a modification date" do
52
+ expect(document).to respond_to :modified
53
+ expect(document.modified).to eq(DateTime.new(2008, 7, 8, 17, 31, 23))
54
+ end
55
+
56
+ it "has a creation date" do
57
+ expect(document).to respond_to :created
58
+ expect(document.created).to eq(DateTime.new(2008, 7, 8, 17, 31, 24))
59
+ end
60
+
61
+ it "has a publication date" do
62
+ expect(document).to respond_to :published
63
+ expect(document.published).to eq(DateTime.new(2008, 7, 8, 17, 31, 25))
64
+ end
65
+
66
+ it "has an owner" do
67
+ expect(document).to respond_to :owner
68
+ expect(document.owner).to be(owner)
69
+ end
70
+
71
+ it "has a link to gliffy editor" do
72
+ return_url = "sample/url"
73
+ return_text = "RETURN TEXT"
74
+
75
+ api.should_receive(
76
+ :web
77
+ ).with(
78
+ "/gliffy/",
79
+ hash_including(
80
+ :launchDiagramId => document_id,
81
+ :returnURL => return_url,
82
+ :returnButtonText => return_text
83
+ )
84
+ ).and_return(
85
+ "http://www.gliffy.com/gliffy/?launchDiagramId=#{document.id}&returnURL=#{return_url}&returnButtonText=#{return_text}"
86
+ )
87
+
88
+ link = document.editor(return_url, return_text)
89
+
90
+ expect(link).to match '/gliffy/'
91
+ expect(link).to match 'launchDiagramId='
92
+ expect(link).to match document.id.to_s
93
+ expect(link).to match 'returnURL='
94
+ expect(link).to match return_url
95
+ expect(link).to match 'returnButtonText='
96
+ expect(link).to match return_text
97
+ end
98
+
99
+ it "has an PNG image" do
100
+ expect(document).to respond_to :png
101
+ expect(document.png).to be_instance_of Gliffy::Document::PNG
102
+ end
103
+
104
+ it "has singleton-life behavior" do
105
+ doc1 = Gliffy::Document.load(owner, response.node("//g:document"))
106
+ expect(doc1).to be document
107
+ end
108
+ end
@@ -0,0 +1,175 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Gliffy::Folder do
5
+ let(:account_id) { 100 }
6
+ let(:api) { double(Gliffy::API) }
7
+ let(:account) { double(Gliffy::Account, :api => api, :id => account_id) }
8
+
9
+ subject(:folder) do
10
+ Gliffy::Folder.load(
11
+ account,
12
+ Gliffy::API::Response.new(
13
+ fixture('folder')
14
+ ).node("//g:folders/g:folder[1]")
15
+ )
16
+ end
17
+
18
+ it "has a name" do
19
+ expect(folder).to respond_to :name
20
+ expect(folder.name).to eq "ROOT"
21
+ end
22
+
23
+ it "has a path" do
24
+ expect(folder).to respond_to :path
25
+ expect(folder.path).to eq "ROOT"
26
+ end
27
+
28
+ it "has a list of documents" do
29
+ expect(folder).to respond_to :documents
30
+ end
31
+
32
+ describe "root folder" do
33
+ it "knows it is root" do
34
+ expect(folder.root?).to be_true
35
+ end
36
+
37
+ it "has no parent" do
38
+ expect(folder.parent).to be_nil
39
+ end
40
+ end
41
+
42
+ describe "document list" do
43
+ it "is loaded from API" do
44
+ api.should_receive(
45
+ :get
46
+ ).and_return(
47
+ Gliffy::API::Response.new(fixture("documents"))
48
+ )
49
+
50
+ folder.documents
51
+ end
52
+
53
+ it "has correct length" do
54
+ api.stub(
55
+ :get
56
+ ).and_return(
57
+ Gliffy::API::Response.new(fixture("documents"))
58
+ )
59
+
60
+ expect(folder.documents.length).to eq 3
61
+ end
62
+
63
+ it "is empty when API returns appropriate response" do
64
+ api.stub(
65
+ :get
66
+ ).and_return(
67
+ Gliffy::API::Response.new(fixture("documents-empty"))
68
+ )
69
+
70
+ expect(folder.documents.length).to eq 0
71
+ end
72
+ end
73
+
74
+ it "has nested folders" do
75
+ expect(folder).to respond_to :folders
76
+ end
77
+
78
+ describe "folder list" do
79
+ subject(:children) { folder.folders }
80
+
81
+ it { should respond_to :length }
82
+ it { should respond_to :[] }
83
+ it "has corrent length" do
84
+ expect(children.length).to eq 4
85
+ end
86
+ end
87
+
88
+ describe "first-level folder 'Burns Top Secret'" do
89
+ subject(:first_child) { folder.folders[0] }
90
+
91
+ it "has correct parent" do
92
+ expect(first_child.parent).to be folder
93
+ end
94
+
95
+ it "has correct name" do
96
+ expect(first_child.name).to eq "Burns Top Secret"
97
+ end
98
+
99
+ it "has correct path" do
100
+ expect(first_child.path).to eq "ROOT/Burns Top Secret"
101
+ end
102
+
103
+ it "has correct number of children" do
104
+ expect(first_child.folders).to eq []
105
+ end
106
+
107
+ it "knows it is not root" do
108
+ expect(first_child.root?).to be_false
109
+ end
110
+ end
111
+
112
+ describe "first-level folder 'Simsons Family'" do
113
+ subject(:second_child) { folder.folders[3] }
114
+
115
+ it "has correct parent" do
116
+ expect(second_child.parent).to be folder
117
+ end
118
+
119
+ it "has correct name" do
120
+ expect(second_child.name).to eq "Simpsons Family"
121
+ end
122
+
123
+ it "has correct path" do
124
+ expect(second_child.path).to eq "ROOT/Simpsons Family"
125
+ end
126
+
127
+ it "has corrent number of children" do
128
+ expect(second_child.folders.length).to eq 2
129
+ end
130
+
131
+ it "knows it is not root" do
132
+ expect(second_child.root?).to be_false
133
+ end
134
+
135
+ describe "second-level folder 'Maggie and Lisas Stuff'" do
136
+ subject(:nested_child) { second_child.folders[1] }
137
+
138
+ it "has corrent parent" do
139
+ expect(nested_child.parent).to be second_child
140
+ end
141
+
142
+ it "has correct name" do
143
+ expect(nested_child.name).to eq "Maggie and Lisas Stuff"
144
+ end
145
+
146
+ it "has correct path" do
147
+ expect(nested_child.path).to eq "ROOT/Simpsons Family/Maggie and Lisas Stuff"
148
+ end
149
+
150
+ it "knows it is not root" do
151
+ expect(nested_child.root?).to be_false
152
+ end
153
+ end
154
+ end
155
+
156
+ context "when assigning a parent" do
157
+ context "with valid path" do
158
+ it "updates parent" do
159
+ f1 = Gliffy::Folder.new(account, "F1", "/ROOT/F1", [])
160
+ f2 = Gliffy::Folder.new(account, "F2", "/ROOT/F1/F2", [])
161
+
162
+ f2.parent = f1
163
+ expect(f2.parent).to be f1
164
+ end
165
+ end
166
+
167
+ context "with invalid path" do
168
+ it "raises an error" do
169
+ f1 = Gliffy::Folder.new(@account, "F1", "/ROOT/F1", [])
170
+ f2 = Gliffy::Folder.new(@account, "F2", "/ROOT/F2", [])
171
+ expect { f1.parent = f2 }.to raise_error
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gliffy do
4
+ it "knows the global API entry point for generic calls" do
5
+ expect(Gliffy).to respond_to :api_root
6
+ expect(Gliffy.api_root).to be_an_instance_of(String)
7
+ end
8
+
9
+ it "knows the global web entry point for generating editor-related URLs" do
10
+ expect(Gliffy).to respond_to :web_root
11
+ expect(Gliffy.web_root).to be_an_instance_of(String)
12
+ end
13
+
14
+ it "provides a default application name value" do
15
+ expect(Gliffy).to respond_to :default_application_name
16
+ expect(Gliffy.default_application_name).to be_an_instance_of(String)
17
+ end
18
+
19
+ describe "API entry point" do
20
+ it "points to a resource at Gliffy site" do
21
+ expect(Gliffy.api_root).to include("gliffy.com")
22
+ end
23
+
24
+ it "is protocol-agnostic" do
25
+ expect(Gliffy.api_root).to_not include("http")
26
+ expect(Gliffy.api_root).to_not include("https")
27
+ end
28
+ end
29
+
30
+ describe "Web entry point" do
31
+ it "points to a resource at Gliffy site" do
32
+ expect(Gliffy.web_root).to include("gliffy.com")
33
+ end
34
+
35
+ it "is protocol-agnostic" do
36
+ expect(Gliffy.api_root).to_not include("http")
37
+ expect(Gliffy.api_root).to_not include("https")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ require 'rspec'
2
+ require 'nokogiri'
3
+
4
+ require 'simplecov'
5
+ SimpleCov.command_name "test:units"
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ add_filter '/lib/gliffy/oauth/'
9
+ end
10
+
11
+ require 'gliffy'
12
+
13
+ def fixture(filename, substitutions = {})
14
+ Nokogiri::XML(
15
+ fixture_xml(filename, substitutions)
16
+ )
17
+ end
18
+
19
+ def fixture_xml(filename, substitutions = {})
20
+ raw_document = IO.read(
21
+ File.join(
22
+ File.dirname(__FILE__),
23
+ "fixtures",
24
+ "#{filename}.xml"
25
+ )
26
+ )
27
+
28
+ raw_document % substitutions
29
+ end
30
+
31
+ RSpec.configure do |config|
32
+ config.expect_with :rspec do |c|
33
+ c.syntax = :expect
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gliffy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Konstantin Burnaev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: http_logger
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A simple Gliffy REST API wrapper.
127
+ email: kbourn@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - lib/gliffy/api/facade.rb
133
+ - lib/gliffy/api/response.rb
134
+ - lib/gliffy/oauth/helper.rb
135
+ - lib/gliffy/document_png.rb
136
+ - lib/gliffy/api.rb
137
+ - lib/gliffy/folder.rb
138
+ - lib/gliffy/document.rb
139
+ - lib/gliffy/account.rb
140
+ - lib/gliffy.rb
141
+ - spec/fixtures/folder.xml
142
+ - spec/fixtures/document.xml
143
+ - spec/fixtures/account.xml
144
+ - spec/fixtures/documents.xml
145
+ - spec/fixtures/documents-empty.xml
146
+ - spec/fixtures/token.xml
147
+ - spec/lib/gliffy/account_spec.rb
148
+ - spec/lib/gliffy/api/facade_spec.rb
149
+ - spec/lib/gliffy/api/response_spec.rb
150
+ - spec/lib/gliffy/folder_spec.rb
151
+ - spec/lib/gliffy/document_png_spec.rb
152
+ - spec/lib/gliffy/document_spec.rb
153
+ - spec/lib/gliffy/api_spec.rb
154
+ - spec/lib/gliffy_spec.rb
155
+ - spec/spec_helper.rb
156
+ - README.md
157
+ homepage: https://github.com/bkon/gliffy
158
+ licenses: []
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.23
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Gliffy API client
181
+ test_files: []