doc_juan 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,8 @@ module DocJuan
9
9
  end
10
10
 
11
11
  class Configuration
12
- attr_accessor :host, :secret
12
+ attr_accessor :host, :secret,
13
+ :username, :password
13
14
  end
14
15
 
15
16
  end
@@ -13,6 +13,9 @@ module DocJuan
13
13
  def initialize url, filename, options = {}
14
14
  @url = url
15
15
  @filename = filename.to_s
16
+
17
+ options = {} unless options
18
+ options = options.merge authentication_credentials if has_authentication_credentials?
16
19
  @options = Hash[(options || {}).sort]
17
20
 
18
21
  raise NoSecretGivenError if secret_key == ''
@@ -58,5 +61,16 @@ module DocJuan
58
61
  def secret_key
59
62
  DocJuan.config.secret.to_s.strip
60
63
  end
64
+
65
+ def authentication_credentials
66
+ {
67
+ username: DocJuan.config.username,
68
+ password: DocJuan.config.password
69
+ }
70
+ end
71
+
72
+ def has_authentication_credentials?
73
+ authentication_credentials.values.compact.any?
74
+ end
61
75
  end
62
76
  end
@@ -1,3 +1,3 @@
1
1
  module DocJuan
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -3,13 +3,30 @@ require_relative 'spec_helper'
3
3
  require_relative '../lib/doc_juan/config.rb'
4
4
 
5
5
  describe DocJuan::Configuration do
6
+ after :each do
7
+ DocJuan.config.secret = nil
8
+ DocJuan.config.host = nil
9
+ DocJuan.config.username = nil
10
+ DocJuan.config.password = nil
11
+ end
12
+
13
+ it 'is configurable' do
14
+ DocJuan.config.secret = 'very-secret'
15
+ DocJuan.config.host = 'http://my-doc-juan-host.com'
16
+ DocJuan.config.username = 'a-username'
17
+ DocJuan.config.password = 'the-password'
18
+
19
+ DocJuan.config.secret.must_equal 'very-secret'
20
+ DocJuan.config.host.must_equal 'http://my-doc-juan-host.com'
21
+ DocJuan.config.username.must_equal 'a-username'
22
+ DocJuan.config.password.must_equal 'the-password'
23
+ end
24
+
6
25
  it 'is configurable with a block' do
7
26
  DocJuan.configure do |config|
8
27
  config.secret = 'very-secret'
9
- config.host = 'http://my-doc-juan-host.com'
10
28
  end
11
29
 
12
30
  DocJuan.config.secret.must_equal 'very-secret'
13
- DocJuan.config.host.must_equal 'http://my-doc-juan-host.com'
14
31
  end
15
32
  end
@@ -70,6 +70,36 @@ describe DocJuan::UrlGenerator do
70
70
  }.must_raise DocJuan::NoSecretGivenError
71
71
  end
72
72
 
73
+ describe '#authentication' do
74
+ before :each do
75
+ DocJuan.config.username = 'xkcd'
76
+ DocJuan.config.password = 'correct horse battery staple'
77
+ end
78
+
79
+ after :each do
80
+ DocJuan.config.username = nil
81
+ DocJuan.config.password = nil
82
+ end
83
+
84
+ it 'knows if authentication credentials is added' do
85
+ subject.has_authentication_credentials?.must_equal true
86
+ end
87
+
88
+ it 'knows if authentication credentials is missing' do
89
+ DocJuan.config.username = nil
90
+ DocJuan.config.password = nil
91
+
92
+ subject.has_authentication_credentials?.must_equal false
93
+ end
94
+
95
+
96
+ it 'appends username and password to options if set as config variables' do
97
+ subject.options[:username].must_equal 'xkcd'
98
+ subject.options[:password].must_equal 'correct horse battery staple'
99
+ end
100
+
101
+ end
102
+
73
103
  it 'compiles into a seed string for the public key computation' do
74
104
  subject.seed_string.must_equal 'filename:file.pdf-options_print_stylesheet:true-options_size:A4-options_title:The Site-url:http://example.com'
75
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doc_juan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,12 +45,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
+ segments:
49
+ - 0
50
+ hash: -3331118814664929665
48
51
  required_rubygems_version: !ruby/object:Gem::Requirement
49
52
  none: false
50
53
  requirements:
51
54
  - - ! '>='
52
55
  - !ruby/object:Gem::Version
53
56
  version: '0'
57
+ segments:
58
+ - 0
59
+ hash: -3331118814664929665
54
60
  requirements: []
55
61
  rubyforge_project:
56
62
  rubygems_version: 1.8.10