wcc-api 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d0d85a20f019b951bef1ae2da1975d22c541af6
4
- data.tar.gz: adb5cd3c3c01bc1492488a56125429c9ba0647d8
3
+ metadata.gz: 74231ceb352ccd172873342f6505b620cf239380
4
+ data.tar.gz: d4ecba5f2d57c5ed15b361362e11e4dca1c17906
5
5
  SHA512:
6
- metadata.gz: 74a49e4005e9a8b621aae1fb71513b30aa965e3a1575d58efaa1b7e2e7d03a967953a8b77c95eefbe56637510a870d3e168410fd2ef74cbfc2f024b038e93bd8
7
- data.tar.gz: f65f84b847eb889eeb9e66284465427ccb73f072706a43dbaf02390461676f066b94f814ecb4c7905cac57a9d6b079c2a29a82b8b315df245acbb61967642797
6
+ metadata.gz: 50d9e33f6592e94854cc838ae7f5de355ad90c53b961da4de8cd3d6d8c87636f0e8655404c5bb04ab7331b5ab196b1b6c51da998e11119905247eadadd694092
7
+ data.tar.gz: fa178778ec21bb489148291e23dabb36c5e49b7b6d4c044e2e4584f18e93d43c9106f0f4953faf9572e6416282d34456d028823fae53029d98e006cc5f3a019c
@@ -0,0 +1,15 @@
1
+ module WCC::API
2
+ module ControllerHelpers
3
+
4
+ private def set_cache_headers(scope_or_record, options = {})
5
+ options = {public: true, must_revalidate: true}.merge!(options)
6
+
7
+ if expiry = options.delete(:expiry)
8
+ expires_in expiry, options.slice(:public, :must_revalidate)
9
+ end
10
+
11
+ fresh_when scope_or_record, options.slice(:etag, :public, :last_modified)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ RSpec.shared_examples_for "cached resource defaults" do
2
+ it "sets etag" do
3
+ expect(response.etag).to_not be_nil
4
+ end
5
+
6
+ it "sets public: true" do
7
+ expect(response.cache_control[:public]).to be_truthy
8
+ end
9
+ end
10
+
11
+ RSpec.shared_examples_for "cached member resource" do
12
+ include_examples "cached resource defaults"
13
+
14
+ it "sets last modified" do
15
+ expect(response.last_modified).to_not be_nil
16
+ end
17
+
18
+ it "does not set max age" do
19
+ expect(response.cache_control[:max_age]).to be_nil
20
+ end
21
+
22
+ it "does not set must_revalidate" do
23
+ expect(response.cache_control[:must_revalidate]).to be_nil
24
+ end
25
+ end
26
+
27
+ RSpec.shared_examples_for "cached collection resource" do |max_age|
28
+ include_examples "cached resource defaults"
29
+
30
+ it "sets max age" do
31
+ expect(response.cache_control[:max_age]).to eq(max_age.to_s)
32
+ end
33
+
34
+ it "sets must_revalidate: true" do
35
+ expect(response.cache_control[:must_revalidate]).to be_truthy
36
+ end
37
+
38
+ it "does not set last modified" do
39
+ expect(response.last_modified).to be_nil
40
+ end
41
+ end
data/lib/wcc/api/rspec.rb CHANGED
@@ -1,3 +1,4 @@
1
- require 'wcc/api/rspec/pagination_examples'
1
+ require 'wcc/api/rspec/cache_header_examples'
2
2
  require 'wcc/api/rspec/collection_matchers'
3
+ require 'wcc/api/rspec/pagination_examples'
3
4
 
@@ -1,5 +1,5 @@
1
1
  module WCC
2
2
  module API
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/wcc/api.rb CHANGED
@@ -13,5 +13,6 @@ end
13
13
 
14
14
  require 'wcc/api/base_query'
15
15
  require 'wcc/api/json'
16
+ require 'wcc/api/controller_helpers'
16
17
  require 'wcc/api/view_helpers'
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wcc-base
@@ -66,10 +66,12 @@ files:
66
66
  - Rakefile
67
67
  - lib/wcc/api.rb
68
68
  - lib/wcc/api/base_query.rb
69
+ - lib/wcc/api/controller_helpers.rb
69
70
  - lib/wcc/api/json.rb
70
71
  - lib/wcc/api/json/pagination.rb
71
72
  - lib/wcc/api/railtie.rb
72
73
  - lib/wcc/api/rspec.rb
74
+ - lib/wcc/api/rspec/cache_header_examples.rb
73
75
  - lib/wcc/api/rspec/collection_matchers.rb
74
76
  - lib/wcc/api/rspec/pagination_examples.rb
75
77
  - lib/wcc/api/version.rb