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 14, 2016
1 parent 1557a93 commit b2e5ce0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 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, except: [:show, :show_featured]

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
5 changes: 0 additions & 5 deletions spec/requests/api/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def json
end

describe 'with languages that exist' do

include_context "shared language pages" do
[:de,:fr,:en,:es].each do |language_code|
it "in #{language_code}, it gets pages only in that language" do
Expand All @@ -73,7 +72,6 @@ def json
end
end
end

end
end

Expand All @@ -91,7 +89,6 @@ def json
end

context 'with languages' do

describe 'with language that does not exist' do
it 'returns json with error' do
get api_pages_featured_path, {language: 'klingon'}
Expand All @@ -110,8 +107,6 @@ def json
end
end
end

end

end
end

0 comments on commit b2e5ce0

Please sign in to comment.