Skip to content

Commit fef82eb

Browse files
Deprecated include_draft method
1 parent 859e315 commit fef82eb

10 files changed

Lines changed: 68 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test
44
doc
55
spec-integration
66
coverage
7+
spec/.env.test
78
\.yardoc
89
.DS_Store
910
.bundle/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## CHANGELOG
22

3+
## Version 0.8.5
4+
### Date: 5th-June-2026
5+
### Deprecated
6+
- `Query#include_draft` is deprecated. The Content Delivery API returns published content only; the `include_draft` query parameter has no effect. Use Live Preview with the Preview Service to preview unpublished entries, or the Content Management API to work with draft content.
7+
38
## Version 0.8.4
49
### Date: 15th-April-2026
510
### Security and Compatibility

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
contentstack (0.8.4)
4+
contentstack (0.8.5)
55
activesupport (>= 3.2)
66
contentstack_utils (~> 1.2)
77

@@ -39,12 +39,12 @@ GEM
3939
hashdiff (1.2.1)
4040
i18n (1.14.8)
4141
concurrent-ruby (~> 1.0)
42-
json (2.19.4)
42+
json (2.19.5)
4343
logger (1.7.0)
44-
minitest (6.0.5)
44+
minitest (6.0.6)
4545
drb (~> 2.0)
4646
prism (~> 1.5)
47-
nokogiri (1.19.2-arm64-darwin)
47+
nokogiri (1.19.3-arm64-darwin)
4848
racc (~> 1.4)
4949
prism (1.9.0)
5050
public_suffix (7.0.5)
@@ -77,7 +77,7 @@ GEM
7777
addressable (>= 2.8.0)
7878
crack (>= 0.3.2)
7979
hashdiff (>= 0.4.0, < 2.0.0)
80-
yard (0.9.43)
80+
yard (0.9.44)
8181

8282
PLATFORMS
8383
arm64-darwin-22

lib/contentstack/query.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -565,16 +565,19 @@ def include_embedded_items()
565565
self
566566
end
567567

568-
# Include objects in 'Draft' mode in response
569-
#
570-
# Example
571-
#
572-
# @query = @stack.content_type('product').query
573-
# @query.include_draft
574-
#
575-
# @return [Contentstack::Query]
576-
def include_draft(flag=true)
577-
@query[:include_draft] = flag
568+
# @deprecated since 0.8.5 The Content Delivery API returns published content only.
569+
# Unpublished or draft entries are not available through CDA queries. Use Live Preview
570+
# with the Preview Service, or the Content Management API, to access unpublished content.
571+
#
572+
# @return [Contentstack::Query]
573+
def include_draft(_flag=true)
574+
warn(
575+
"Contentstack: Query#include_draft is deprecated and has no effect on the Content " \
576+
"Delivery API, which returns published content only. To preview unpublished entries, " \
577+
"use Live Preview with the Preview Service. To manage or fetch draft entries, use " \
578+
"the Content Management API.",
579+
uplevel: 1
580+
)
578581
self
579582
end
580583

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.8.4"
2+
VERSION = "0.8.5"
33
end

skills/testing/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ description: Use when writing or fixing RSpec examples, WebMock stubs, JSON fixt
3030

3131
### Helpers
3232

33-
- **`create_client`** and **`create_preview_client`** in **`spec_helper`** build clients using **`ENV['API_KEY']`**, **`ENV['DELIVERY_TOKEN']`**, **`ENV['ENVIRONMENT']`** — tests should not rely on real credentials; stubs supply responses.
33+
- **`create_client`** and **`create_preview_client`** in **`spec_helper`** build clients using **`ENV['API_KEY']`**, **`ENV['DELIVERY_TOKEN']`**, **`ENV['ENVIRONMENT']`**. Copy **`spec/.env.test.example`** to **`spec/.env.test`** (gitignored) for local runs without exporting env vars; CLI/env values already set take precedence. Tests use WebMock stubs and do not require live API calls.
3434

3535
### Coverage
3636

spec/.env.test.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copy to spec/.env.test and fill in your stack credentials.
2+
# spec/.env.test is gitignored — do not commit real tokens.
3+
#
4+
# bundle exec rspec
5+
6+
API_KEY=your_stack_api_key
7+
DELIVERY_TOKEN=your_delivery_token
8+
ENVIRONMENT=development
9+
# Optional: only needed for custom CDN host tests
10+
# HOST=cdn.contentstack.io

spec/query_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@
165165
expect(data.first.fields[:locale]).not_to be nil
166166
end
167167

168-
it "should get data using `include_draft` method" do
169-
data = category_query.include_draft.fetch
168+
it "warns when `include_draft` is called and does not send include_draft to the API" do
169+
query = category_query
170+
expect {
171+
query.include_draft
172+
}.to output(/Query#include_draft is deprecated/).to_stderr
173+
expect(query.query).not_to have_key(:include_draft)
174+
data = query.fetch
170175
expect(data.length).to eq 5
171176
end
172177

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
require 'webmock/rspec'
1717
WebMock.disable_net_connect!(allow_localhost: true)
1818

19+
require_relative 'support/load_test_env'
20+
1921
require 'simplecov'
2022
SimpleCov.start
2123

spec/support/load_test_env.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Loads optional local test credentials from spec/.env.test (gitignored).
2+
# Existing ENV values are not overwritten, so CLI exports still take precedence.
3+
module ContentstackTestEnv
4+
ENV_FILE = File.expand_path("../.env.test", __dir__).freeze
5+
6+
def self.load!
7+
return unless File.file?(ENV_FILE)
8+
9+
File.foreach(ENV_FILE) do |line|
10+
line = line.strip
11+
next if line.empty? || line.start_with?("#")
12+
13+
key, value = line.split("=", 2)
14+
next if key.nil? || value.nil?
15+
16+
key = key.strip
17+
value = value.strip.delete_prefix('"').delete_suffix('"')
18+
ENV[key] = value unless ENV.key?(key) && !ENV[key].to_s.empty?
19+
end
20+
end
21+
end
22+
23+
ContentstackTestEnv.load!

0 commit comments

Comments
 (0)