Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Return 'get_page' before action, and add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Jul 13, 2016
1 parent 1557a93 commit ad81f2b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app/controllers/api/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'rack'

class Api::PagesController < ApplicationController

before_action :set_language, only: [:show, :show_featured]
before_action :get_page

layout false

Expand All @@ -16,7 +14,6 @@ def update
end

def share_rows
get_page
render json: (@page.shares.map do |s|
{html: render_to_string(partial: "share/#{s.name}s/summary_row", locals: {share: s, page: @page})}
end)
Expand All @@ -38,7 +35,6 @@ def show_featured
else
render json: pages_by_language.where(featured: true)
end

end

private
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/api/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'

describe Api::PagesController do
let(:page) { instance_double('Page', id: 1, to_param: '1') }
let(:page_updater) { double(update: true, refresh?: true) }

before do
allow(Page).to receive(:find){ page }
allow(PageUpdater).to receive(:new) { page_updater }
end

describe 'PUT update' do
before do
put :update, id: 1
end

it 'finds page' do
expect(Page).to have_received(:find).with('1')
end

context 'PageUpdater' do
it 'is instantiated' do
expect(PageUpdater).to have_received(:new).with(page, "http://test.host/pages/1")
end

it 'calls update with params' do
expect(page_updater).to have_received(:update).with({})
end
end
end
end

0 comments on commit ad81f2b

Please sign in to comment.