diff --git a/.travis.yml b/.travis.yml index 6d0e6c9715..3a3cf71799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,12 @@ env: - DB=postgresql EXTENSION=pages - DB=postgresql EXTENSION=images - DB=postgresql EXTENSION=resources + - DB=postgresql EXTENSION=api - DB=mysql EXTENSION=core - DB=mysql EXTENSION=pages - DB=mysql EXTENSION=images - DB=mysql EXTENSION=resources + - DB=mysql EXTENSION=api notifications: email: true irc: diff --git a/Gemfile b/Gemfile index b1195b6209..0c316ab117 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ path "./" do gem "refinerycms-images" gem "refinerycms-pages" gem "refinerycms-resources" + gem "refinerycms-api" end gem 'spring' diff --git a/api/app/controllers/refinery/api/graphql_controller.rb b/api/app/controllers/refinery/api/graphql_controller.rb new file mode 100644 index 0000000000..b8afb935b1 --- /dev/null +++ b/api/app/controllers/refinery/api/graphql_controller.rb @@ -0,0 +1,27 @@ +module Refinery + module Api + class GraphqlController < Refinery::AdminController + + def execute + query = params[:query] + variables = params[:variables] || {} + + begin + result = Refinery::Api::GraphqlSchema.execute(query, variables: variables, context: context) + rescue => error + result = { errors: [{ message: error.message }] } + end + + render json: result + end + + private + + def context + { + current_user: current_refinery_user + } + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/page_field.rb b/api/app/graph/refinery/api/fields/pages/page_field.rb new file mode 100644 index 0000000000..fc6609f303 --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/page_field.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + class PageField < GraphQL::Schema::Field + name 'Page' + description 'Find a page by ID' + + type Types::Pages::PageType + argument :id, !types.ID + + resolve -> (obj, args, ctx) { + Refinery::Page.find_by_id(args[:id]) + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/pages_field.rb b/api/app/graph/refinery/api/fields/pages/pages_field.rb new file mode 100644 index 0000000000..a3a1faafd0 --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/pages_field.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + class PagesField < GraphQL::Schema::Field + name 'Pages' + description 'Find all pages' + + type types[Types::Pages::PageType] + + resolve -> (obj, args, ctx) { + Refinery::Page.all + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb new file mode 100644 index 0000000000..b2b8b79534 --- /dev/null +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Refinery + module Api + class GraphqlSchema < GraphQL::Schema + query Types::QueryType + mutation Types::MutationType + + resolve_type -> (obj, args, ctx) { + type_name = obj.class.name + Schema.types[type_name] + } + end + end +end diff --git a/api/app/graph/refinery/api/inputs/pages/page_input.rb b/api/app/graph/refinery/api/inputs/pages/page_input.rb new file mode 100644 index 0000000000..814bdcbe72 --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_input.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Pages + class PageInput < GraphQL::Schema::InputObject + name 'PageInput' + + input_field :parent_id, types.Int + input_field :path, types.String + input_field :show_in_menu, types.Boolean + input_field :link_url, types.String + input_field :menu_match, types.String + input_field :deletable, types.Boolean + input_field :draft, types.Boolean + input_field :skip_to_first_child, types.Boolean + input_field :lft, types.Int + input_field :rgt, types.Int + input_field :depth, types.Int + input_field :view_template, types.String + input_field :layout_template, types.String + input_field :locale, types.String + input_field :title, types.String + input_field :custom_slug, types.String + input_field :menu_title, types.String + input_field :slug, types.String + input_field :meta_description, types.String + input_field :browser_title, types.String + + input_field :parts, types[Inputs::Pages::PagePartInput] + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/inputs/pages/page_part_input.rb b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb new file mode 100644 index 0000000000..8ba01e534a --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Pages + class PagePartInput < GraphQL::Schema::InputObject + name 'PagePartInput' + + input_field :slug, types.String + input_field :position, types.Int + input_field :title, types.String + + input_field :locale, types.String + input_field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/create.rb b/api/app/graph/refinery/api/mutations/pages/create.rb new file mode 100644 index 0000000000..b6e87026ff --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/create.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Create < GraphQL::Schema::Mutation + name 'CreatePage' + description 'Create a page' + + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + page = Refinery::Page.create!(inputs[:page]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/delete.rb b/api/app/graph/refinery/api/mutations/pages/delete.rb new file mode 100644 index 0000000000..7a04b657a7 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/delete.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Delete < GraphQL::Schema::Mutation + name 'DeletePage' + + input_field :id, !types.ID + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + page = Refinery::Page.destroy(inputs[:id]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/update.rb b/api/app/graph/refinery/api/mutations/pages/update.rb new file mode 100644 index 0000000000..db33db4b26 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/update.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module Pages + class Update < GraphQL::Schema::Mutation + name 'UpdatePage' + description 'Create a page' + + input_field :id, !types.ID + input_field :page, !Inputs::Pages::PageInput + + return_field :page, Types::Pages::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + page = Refinery::Page.update(inputs[:id], inputs[:page]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/active_record_interface.rb b/api/app/graph/refinery/api/types/active_record_interface.rb new file mode 100644 index 0000000000..508e44b904 --- /dev/null +++ b/api/app/graph/refinery/api/types/active_record_interface.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + ActiveRecordInterface = GraphQL::InterfaceType.define do + name "ActiveRecord" + description "Active Record Interface" + + field :id, !types.ID + field :updated_at do + type Types::DateType + resolve -> (obj, args, ctx) { + obj.updated_at + } + end + field :created_at do + type Types::DateType + resolve -> (obj, args, ctx) { + obj.created_at + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_interface.rb b/api/app/graph/refinery/api/types/base_interface.rb new file mode 100644 index 0000000000..500c20d2da --- /dev/null +++ b/api/app/graph/refinery/api/types/base_interface.rb @@ -0,0 +1,9 @@ +module Refinery + module Api + module Types + class BaseInterface + include GraphQL::Schema::Interface + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/base_object.rb b/api/app/graph/refinery/api/types/base_object.rb new file mode 100644 index 0000000000..18cb6f185c --- /dev/null +++ b/api/app/graph/refinery/api/types/base_object.rb @@ -0,0 +1,8 @@ +module Refinery + module Api + module Types + class BaseObject < GraphQL::Schema::Object + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/date_type.rb b/api/app/graph/refinery/api/types/date_type.rb new file mode 100644 index 0000000000..ec22f6ba21 --- /dev/null +++ b/api/app/graph/refinery/api/types/date_type.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + DateType = GraphQL::ScalarType.define do + name "Date" + description "Valid date format (parsable by Ruby's Date.parse)" + + coerce_input -> (value, context) do + begin Date.parse(value) + value.to_datetime + rescue ArgumentError => error + context.errors << error.message + end + end + + coerce_result -> (value, context) do + value.to_datetime + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/mutation_type.rb b/api/app/graph/refinery/api/types/mutation_type.rb new file mode 100644 index 0000000000..8ade6f2e31 --- /dev/null +++ b/api/app/graph/refinery/api/types/mutation_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + class MutationType < Types::BaseObject + name 'Mutation' + description 'The mutation root for this schema' + + field :createPage, mutation: Mutations::Pages::Create + field :updatePage, mutation: Mutations::Pages::Update + field :deletePage, mutation: Mutations::Pages::Delete + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_part_type.rb b/api/app/graph/refinery/api/types/pages/page_part_type.rb new file mode 100644 index 0000000000..b57a23f724 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_part_type.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + class PagePartType < GraphQL::Schema::Object + name "PagePart" + description "A PagePart" + + interfaces [Types::ActiveRecordInterface] + + field :slug, types.String + field :position, types.Int + field :title, types.String + + field :locale, types.String + field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_type.rb b/api/app/graph/refinery/api/types/pages/page_type.rb new file mode 100644 index 0000000000..569b6119c6 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + class PageType < GraphQL::Schema::Object + name "Page" + description "A Page" + + interfaces [Types::ActiveRecordInterface] + + field :parent_id, types.Int + field :path, types.String + field :show_in_menu, types.Boolean + field :link_url, types.String + field :menu_match, types.String + field :deletable, types.Boolean + field :draft, types.Boolean + field :skip_to_first_child, types.Boolean + field :lft, types.Int + field :rgt, types.Int + field :depth, types.Int + field :view_template, types.String + field :layout_template, types.String + field :locale, types.String + field :title, types.String + field :custom_slug, types.String + field :menu_title, types.String + field :slug, types.String + field :meta_description, types.String + field :browser_title, types.String + + field :parts do + type types[Types::Pages::PagePartType] + + resolve -> (obj, args, ctx) { + obj.parts.order(:position) + } + end + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb new file mode 100644 index 0000000000..13cb7fee1d --- /dev/null +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + class QueryType < Types::BaseObject + name 'Query' + description 'The query root of this schema' + + field :page, field: Fields::Pages::PageField + field :pages, field: Fields::Pages::PagesField + end + end + end +end \ No newline at end of file diff --git a/api/config/routes.rb b/api/config/routes.rb new file mode 100644 index 0000000000..5118f2cad5 --- /dev/null +++ b/api/config/routes.rb @@ -0,0 +1,9 @@ +Refinery::Core::Engine.routes.draw do + namespace :api do + post 'graphql' => 'graphql#execute' + + if Rails.env.development? + mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/#{Refinery::Core.backend_route}/graphql" + end + end +end diff --git a/api/lib/refinery/api.rb b/api/lib/refinery/api.rb new file mode 100644 index 0000000000..2942426761 --- /dev/null +++ b/api/lib/refinery/api.rb @@ -0,0 +1,21 @@ +require 'refinerycms-core' +require 'graphql' +require 'graphiql/rails' + +module Refinery + module Api + require 'refinery/api/engine' + + class << self + attr_writer :root + + def root + @root ||= Pathname.new(File.expand_path('../../../', __FILE__)) + end + + def factory_paths + @factory_paths ||= [ root.join('spec', 'factories').to_s ] + end + end + end +end diff --git a/api/lib/refinery/api/engine.rb b/api/lib/refinery/api/engine.rb new file mode 100644 index 0000000000..14ea3555d0 --- /dev/null +++ b/api/lib/refinery/api/engine.rb @@ -0,0 +1,22 @@ +module Refinery + module Api + class Engine < Rails::Engine + extend Refinery::Engine + isolate_namespace Refinery::Api + + engine_name :refinery_api + + before_inclusion do + Refinery::Plugin.register do |plugin| + plugin.name = "refinerycms_api" + plugin.hide_from_menu = true + plugin.pathname = root + end + end + + config.after_initialize do + Refinery.register_extension(Refinery::Api) + end + end + end +end diff --git a/api/lib/refinerycms-api.rb b/api/lib/refinerycms-api.rb new file mode 100644 index 0000000000..c8f56017b7 --- /dev/null +++ b/api/lib/refinerycms-api.rb @@ -0,0 +1 @@ +require 'refinery/api' diff --git a/api/license.md b/api/license.md new file mode 100644 index 0000000000..a2792fd6c8 --- /dev/null +++ b/api/license.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2017 [Brice Sanchez](http://brice-sanchez.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/api/refinerycms-api.gemspec b/api/refinerycms-api.gemspec new file mode 100644 index 0000000000..0920c93c89 --- /dev/null +++ b/api/refinerycms-api.gemspec @@ -0,0 +1,36 @@ +# Encoding: UTF-8 +require File.expand_path('../../core/lib/refinery/version', __FILE__) + +version = Refinery::Version.to_s + +Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = %q{refinerycms-api} + s.version = version + s.summary = %q{Api extension for Refinery CMS} + s.description = %q{Api extension for Refinery CMS} + s.email = %q{} + s.homepage = %q{http://refinerycms.com} + s.rubyforge_project = %q{refinerycms} + s.authors = ['Brice Sanchez'] + s.license = %q{MIT} + s.require_paths = %w(lib) + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- spec/*`.split("\n") + + # Runtime dependencies + s.add_dependency 'refinerycms-core', version + s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5' + s.add_dependency 'graphiql-rails', '~> 1.4' + + # Development dependencies (usually used for testing) + s.add_development_dependency 'refinerycms-testing', '~> 4.0.0' + + s.required_ruby_version = Refinery::Version.required_ruby_version + + s.cert_chain = [File.expand_path("../../certs/parndt.pem", __FILE__)] + if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) + s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") + end +end \ No newline at end of file diff --git a/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb new file mode 100644 index 0000000000..07d811e4db --- /dev/null +++ b/api/spec/graph/refinery/api/fields/pages/page_field_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Fields + module Pages + describe 'PageField' do + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { { } } + let(:variables) { { } } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +query($id: ID!) { + page(id: $id) { + title + } +} + QUERY + end + + subject { result } + + context "as a normal user" do + let(:variables) do + {'query' => '', 'id' => page.id } + end + + it 'returns a page' do + subject + expect(result['data']['page']['title']).to eq(page.title) + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb new file mode 100644 index 0000000000..dfb8a8db4b --- /dev/null +++ b/api/spec/graph/refinery/api/fields/pages/pages_field_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Fields + module Pages + describe 'PagesField' do + + let!(:pages) { FactoryBot.create_list(:page, 5) } + + let(:context) { { } } + let(:variables) { { } } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +query { + pages { + title + } +} + QUERY + end + + subject { result } + + context "as a normal user" do + it 'returns the pages' do + subject + expect(result['data']['pages'].length).to eq(5) + end + end + end + end + end + end + end diff --git a/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb new file mode 100644 index 0000000000..53d5723233 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/create_page_mutation_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'CreatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: CreatePageInput!) { + create_page(input: $page) { + page { + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'create a page' do + let(:variables) do + { + 'page' => { + 'page' => { + 'title' => 'Test page' + } + } + } + end + + it 'returns the page title of the newly created page' do + subject + expect(result['data']['create_page']['page']['title']).to eq('Test page') + end + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb new file mode 100644 index 0000000000..8d91c662c2 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/delete_page_mutation_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'DeletePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: DeletePageInput!) { + delete_page(input: $page) { + page { + id + } + } +} + QUERY + end + + subject { result } + + context 'Correct page id' do + let(:variables) { {'page' => { 'id' => page.id }} } + + it 'deletes the page' do + subject + expect(Refinery::Page.find_by_id(page.id)).to be(nil) + end + end + end + end + end + end +end diff --git a/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb new file mode 100644 index 0000000000..cb6ea0b5b2 --- /dev/null +++ b/api/spec/graph/refinery/api/mutations/pages/update_page_mutation_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Refinery + module Api + module Mutations + module Pages + describe 'UpdatePageMutation' do + let(:logged_in_user) { Refinery::Core::NilUser.new } + + let!(:page) { FactoryBot.create(:page) } + + let(:context) { {current_user: logged_in_user} } + + let(:result) do + GraphqlSchema.execute( + query_string, + context: context, + variables: variables + ) + end + + let(:query_string) do + <<-QUERY +mutation($page: UpdatePageInput!) { + update_page(input: $page) { + page { + id + title + } + } +} + QUERY + end + + subject { result } + + context 'as an admin' do + context 'update a page' do + let(:variables) do + { + 'page' => { + 'id' => page.id, + 'page' => { + 'title' => 'Updated Test page' + } + } + } + end + + it 'returns the page id and title of the newly created page' do + subject + expect(result['data']['update_page']['page']['id']).to eq(page.id.to_s) + expect(result['data']['update_page']['page']['title']).to eq('Updated Test page') + end + end + end + end + end + end + end +end diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rb new file mode 100644 index 0000000000..ecf8a46790 --- /dev/null +++ b/api/spec/spec_helper.rb @@ -0,0 +1,30 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] ||= 'test' + +if File.exist?(dummy_path = File.expand_path('../dummy/config/environment.rb', __FILE__)) + require dummy_path +elsif File.dirname(__FILE__) =~ %r{vendor/extensions} + # Require the path to the refinerycms application this is vendored inside. + require File.expand_path('../../../../../config/environment', __FILE__) +else + puts "Could not find a config/environment.rb file to require. Please specify this in #{File.expand_path(__FILE__)}" +end + +require 'rspec/rails' +require 'capybara/rspec' + +Rails.backtrace_cleaner.remove_silencers! + +RSpec.configure do |config| + config.mock_with :rspec + config.filter_run :focus => true + config.run_all_when_everything_filtered = true +end + +# Requires supporting files with custom matchers and macros, etc, +# in ./support/ and its subdirectories including factories. +([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{ |p| + Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s] +}.flatten.sort.each do |support_file| + require support_file +end diff --git a/lib/refinery/all.rb b/lib/refinery/all.rb index 721cd018de..5a7f0fd298 100644 --- a/lib/refinery/all.rb +++ b/lib/refinery/all.rb @@ -1,3 +1,3 @@ -%w(core images resources pages).each do |extension| +%w(core images resources pages api).each do |extension| require "refinerycms-#{extension}" end diff --git a/pages/lib/refinery/pages/configuration.rb b/pages/lib/refinery/pages/configuration.rb index b2863e926e..1cdd7db2be 100644 --- a/pages/lib/refinery/pages/configuration.rb +++ b/pages/lib/refinery/pages/configuration.rb @@ -62,7 +62,7 @@ def layout_template_whitelist self.types = Types.registered self.auto_expand_admin_tree = true self.friendly_id_reserved_words = %w( - index new session login logout users refinery admin images + index new session login logout users refinery admin images api ) self.layout_templates_pattern = 'app', 'views', '{layouts,refinery/layouts}', '*html*' self.view_templates_pattern = 'app', 'views', '{pages,refinery/pages}', '*html*'