Skip to content

Commit

Permalink
Add end-to-end Prismic integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Apr 3, 2020
1 parent 3efc459 commit 620188b
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.rspec_status
Gemfile.lock
gemfiles/*.lock
tmp/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ RenderfulClient.render('your_entry_id')
In order to integrate with Prismic, you will first need to add the `prismic.io` gem to your Gemfile:

```ruby
gem 'prismic.io'
gem 'prismic.io', require: 'prismic'
```

Now make sure to install it:
Expand Down
2 changes: 1 addition & 1 deletion lib/renderful/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Renderful
class Client
attr_reader :provider, :components, :cache

def initialize(provider:, components:, cache: Cache::Null)
def initialize(provider:, components:, cache: Cache::Null.new)
@provider = provider
@components = components
@cache = cache
Expand Down
4 changes: 4 additions & 0 deletions renderful.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'appraisal', '~> 2.2'
spec.add_development_dependency 'bundler', '~> 2.1'
spec.add_development_dependency 'capybara', '~> 3.32'
spec.add_development_dependency 'combustion', '~> 1.1'
spec.add_development_dependency 'contentful', '~> 2.11'
spec.add_development_dependency 'gem-release', '~> 2.1'
Expand All @@ -40,4 +41,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
spec.add_development_dependency 'rubocop', '~> 0.79.0'
spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
spec.add_development_dependency 'vcr', '~> 5.1'
spec.add_development_dependency 'view_component', '~> 2.2'
spec.add_development_dependency 'webmock', '~> 3.8'
end
15 changes: 15 additions & 0 deletions spec/integration/prismic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Prismic integration test', type: :feature do
around do |example|
VCR.use_cassette('prismic', &example)
end

it 'renders Contentful entries' do
visit '/prismic'

expect(page.body.strip).to eq('Homepage')
end
end
12 changes: 12 additions & 0 deletions spec/internal/app/components/page_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class PageComponent < ViewComponent::Base
def initialize(entry:, client:)
@entry = entry
@client = client
end

def call
@entry.fields['title'].as_text
end
end
5 changes: 5 additions & 0 deletions spec/internal/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class PagesController < ActionController::Base
def prismic; end
end
1 change: 1 addition & 0 deletions spec/internal/app/views/pages/prismic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= RenderfulPrismicClient.render('XodtshAAACIACgDj', view_context: self) %>
1 change: 0 additions & 1 deletion spec/internal/app/views/renderful/_test.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions spec/internal/config/initializers/renderful.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

RenderfulPrismicClient = Renderful::Client.new(
provider: Renderful::Provider::Prismic.new(prismic: Prismic.api(
'https://renderfultest.cdn.prismic.io/api',
'secret_access_token',
)),
components: {
'page' => PageComponent,
},
cache: Rails.cache,
)
2 changes: 1 addition & 1 deletion spec/internal/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

Rails.application.routes.draw do
# Add your own routes here, or remove this file if you don't have need for it.
get 'prismic', to: 'pages#prismic'
end
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# frozen_string_literal: true

require 'prismic'
require 'view_component'

require 'combustion'
Combustion.initialize! :action_controller, :action_view, :sprockets

require 'rspec/rails'
require 'capybara/rspec'
require 'renderful'
require 'webmock'
require 'vcr'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand All @@ -17,3 +23,8 @@
c.syntax = :expect
end
end

VCR.configure do |config|
config.cassette_library_dir = "spec/vcr_cassettes"
config.hook_into :webmock
end
57 changes: 57 additions & 0 deletions spec/vcr_cassettes/prismic.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 620188b

Please sign in to comment.