middleman-cdn 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abdeed280f1aac94088448fea0eb57cf6d9197b4
4
- data.tar.gz: b035ab9491fd8621f60e3d16801fc561ce293de1
3
+ metadata.gz: c7df50ddbc16cbcc2aad12f23bc81f594664f71c
4
+ data.tar.gz: 2bbb29162f24ed5fb9470847460b3052612ed87b
5
5
  SHA512:
6
- metadata.gz: 70069cc04651195fc537cbdb8ec83b41c656db7c519d7b8ff5a8fa9d127688038c7fb306e547108b9efa739fc0c1def0a88405ef3d42b00a3f25a99005c77eda
7
- data.tar.gz: 4e076e4122b5ab56087670508670fffc9de01fa6bee1944574ec7032c6b3d5a7731c7aec4c6b5497184685ddae72915ef019109386363b40d5f8618bf8cc6e73
6
+ metadata.gz: 6413c23a7d9080e4846e2c73db67736aa03292567b2e85e6d3ee35ba8468f5a0fe27b11ea2bd4d152136a926317019176da5211e402a961dea6a9529b19495c7
7
+ data.tar.gz: 70f29c73716425f684dabf4887fcb262362912de4f5e22b0751412a0fba1a7363297ca845960dbb20092367549291826b72f96f6a6199079cb35a08193a538c9
@@ -24,14 +24,16 @@ module Middleman
24
24
  if options.nil?
25
25
  app_instance = ::Middleman::Application.server.inst
26
26
  unless app_instance.respond_to?(:cdn_options)
27
- raise Error, "ERROR: You need to activate the cdn extension in config.rb.\n#{example_configuration}"
27
+ self.class.say_status(nil, "Error: You need to activate the cdn extension in config.rb.\n#{example_configuration}".light_red)
28
+ raise
28
29
  end
29
30
  options = app_instance.cdn_options
30
31
  end
31
32
  options.filter ||= /.*/
32
33
 
33
34
  if cdns.all? { |cdn| options.public_send(cdn.key.to_sym).nil? }
34
- raise Error, "ERROR: You must specify a config for one of the supported CDNs.\n#{example_configuration}"
35
+ self.class.say_status(nil, "Error: You must specify a config for one of the supported CDNs.\n#{example_configuration}".light_red)
36
+ raise
35
37
  end
36
38
 
37
39
  files = list_files(options.filter)
@@ -56,7 +58,7 @@ module Middleman
56
58
  end
57
59
  end
58
60
 
59
- protected
61
+ private
60
62
 
61
63
  def cdns
62
64
  [
@@ -72,7 +74,7 @@ module Middleman
72
74
  def example_configuration
73
75
  <<-TEXT
74
76
 
75
- The example configuration is:
77
+ Example configuration:
76
78
  activate :cdn do |cdn|
77
79
  #{cdns.map(&:example_configuration).join}
78
80
  cdn.filter = /\.html/i # default /.*/
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency 'fog', '~> 1.9'
21
21
  s.add_dependency 'cloudflare', '~> 2.0'
22
- s.add_dependency 'fastly', '~> 1.1'
23
22
  s.add_dependency 'colorize', '~> 0.7'
24
23
  s.add_dependency 'activesupport', '~> 4.1'
25
24
 
@@ -1,23 +1,108 @@
1
1
  require 'spec_helper'
2
- require 'fog/aws/models/cdn/distributions'
3
2
 
4
3
  describe Middleman::Cli::CDN do
5
- let(:cdn) { described_class.new }
6
- let(:options) do
7
- OpenStruct.new({
8
- cloudflare: nil,
9
- cloudfront: {
10
- access_key_id: 'access_key_id_123',
11
- secret_access_key: 'secret_access_key_123',
12
- distribution_id: 'distribution_id_123',
13
- },
14
- filter: /.*/,
15
- after_build: 'after_build_123'
16
- })
4
+ let(:subject) { described_class.new }
5
+
6
+ describe '.exit_on_failure?' do
7
+ it "should return true" do
8
+ expect(described_class.exit_on_failure?).to eq(true)
9
+ end
10
+ end
11
+
12
+ describe '.say_status' do
13
+ context "defaults" do
14
+ it "should say" do
15
+ described_class.say_status(nil, "a status")
16
+ end
17
+ end
17
18
  end
18
- let(:distribution) { double('distribution', invalidations: double('invalidations')) }
19
19
 
20
- describe '#invalidate' do
21
- # TODO
20
+ describe '#cdn_invalidate' do
21
+ before do
22
+ allow(Dir).to receive(:chdir).with(anything) { |path, &block| block.call }
23
+ allow(Dir).to receive(:glob).with('**/*', File::FNM_DOTMATCH).and_return([".", "index.html", "image.png"])
24
+ allow(File).to receive(:directory?).with(".").and_return(true)
25
+ allow(File).to receive(:directory?).with("index.html").and_return(false)
26
+ allow(File).to receive(:directory?).with("image.png").and_return(false)
27
+ end
28
+
29
+ context "all files matched" do
30
+ context "no cdn provided" do
31
+ let(:options) do
32
+ OpenStruct.new({
33
+ filter: /.*/
34
+ })
35
+ end
36
+
37
+ it "should invalidate the files with only cloudflare" do
38
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to_not receive(:invalidate)
39
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
40
+ expect { subject.cdn_invalidate(options) }.to raise_error(RuntimeError)
41
+ end
42
+ end
43
+
44
+ context "one cdn provided" do
45
+ let(:options) do
46
+ OpenStruct.new({
47
+ cloudflare: {},
48
+ filter: /.*/
49
+ })
50
+ end
51
+
52
+ it "should invalidate the files with only cloudflare" do
53
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/image.png", "/"])
54
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
55
+ subject.cdn_invalidate(options)
56
+ end
57
+ end
58
+
59
+ context "all cdns provided" do
60
+ let(:options) do
61
+ OpenStruct.new({
62
+ cloudflare: {},
63
+ cloudfront: {},
64
+ filter: /.*/
65
+ })
66
+ end
67
+
68
+ it "should invalidate the files with all cdns" do
69
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/image.png", "/"])
70
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/image.png", "/"])
71
+ subject.cdn_invalidate(options)
72
+ end
73
+ end
74
+ end
75
+
76
+ context "some files matched" do
77
+ let(:options) do
78
+ OpenStruct.new({
79
+ cloudflare: {},
80
+ cloudfront: {},
81
+ filter: /\.html/
82
+ })
83
+ end
84
+
85
+ it "should invalidate the files with all cdns" do
86
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/"])
87
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/"])
88
+ subject.cdn_invalidate(options)
89
+ end
90
+ end
91
+
92
+ context "no files matched" do
93
+ let(:options) do
94
+ OpenStruct.new({
95
+ cloudflare: {},
96
+ cloudfront: {},
97
+ filter: /\.htm$/
98
+ })
99
+ end
100
+
101
+ it "should invalidate the files with all cdns" do
102
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to_not receive(:invalidate)
103
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to_not receive(:invalidate)
104
+ subject.cdn_invalidate(options)
105
+ end
106
+ end
22
107
  end
23
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: fastly
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: colorize
57
43
  requirement: !ruby/object:Gem::Requirement