Skip to content

Commit

Permalink
Merge ee34b0a into 050e9ff
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Oct 29, 2020
2 parents 050e9ff + ee34b0a commit 8c7b31b
Show file tree
Hide file tree
Showing 106 changed files with 346 additions and 306 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
@@ -1,13 +1,19 @@
language: ruby
sudo: false
sudo: required
cache:
directories:
- bundler
- travis_phantomjs

rvm:
- 2.5.1

addons:
chrome: stable

services:
- mysql
- postgresql

env:
- DB=mysql
- DB=pg
Expand All @@ -17,12 +23,6 @@ matrix:
- env: DB=pg

before_install:
- "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
- if [ $(phantomjs --version) != '2.1.1' ]; then
rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs;
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2;
tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs;
fi
- 'cp "config.yml.${DB}.travis" "config.yml"'

before_script:
Expand Down
2 changes: 1 addition & 1 deletion .versions.conf
@@ -1 +1 @@
ruby=ruby-2.5.1
ruby=ruby-2.6
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -26,7 +26,7 @@ gemspec
# gem 'debugger'
case config["database"]["type"]
when 'mysql'
gem 'mysql2', '< 0.5', platform: :ruby
gem 'mysql2', '~> 0.5', platform: :ruby
when 'postgresql'
gem 'pg', '~> 0.15'
end
Expand Down
16 changes: 12 additions & 4 deletions lib/releaf/rspec/helpers.rb
Expand Up @@ -54,7 +54,7 @@ def update_resource
end

def create_resource
click_link "Create new resource" unless first("form.new-resource")
click_link "Create new resource" unless first("form.new-resource", minimum: 0)
within "form.new-resource" do
yield
end
Expand Down Expand Up @@ -89,8 +89,8 @@ def close_dialog
def wait_for_all_richtexts
# wait for all ckeditors to fully initialize before moving on.
# otherwise the page sometimes produces random js errors in fast tests
number_of_normal_richtexts = page.all('.field.type-richtext:not(.i18n)').length
number_of_localized_richtexts = page.all('.field.type-richtext.i18n .localization', visible: false).length
number_of_normal_richtexts = page.all('.field.type-richtext:not(.i18n)', wait: 0).length
number_of_localized_richtexts = page.all('.field.type-richtext.i18n .localization', wait: 0, visible: false).length
number_of_richtexts = number_of_normal_richtexts + number_of_localized_richtexts
if (number_of_richtexts > 0)
expect(page).to have_css(".ckeditor-initialized", visible: false, count: number_of_richtexts)
Expand Down Expand Up @@ -208,7 +208,7 @@ def fill_in_richtext(locator, options = {} )
textareas = []
richtext_boxes = all(".field.type-richtext:not(.i18n), .field.type-richtext.i18n .localization.active")
richtext_boxes.each do |richtext_box|
textarea = richtext_box.first(:field, locator, visible: false)
textarea = richtext_box.first(:field, locator, visible: false, minimum: 0)
textareas << textarea if textarea.present?
end

Expand Down Expand Up @@ -254,5 +254,13 @@ def wait_for_nested_item(block_name, item_index)
expect(page).to have_css(".item[data-name=\"#{block_name}\"][data-index=\"#{item_index}\"][style=\"opacity: 1; display: block;\"]")
end

def download_file(url)
require "open-uri"
file = Tempfile.new
file.binmode
file.write(open(url).read)
file.flush
file
end
end
end
Expand Up @@ -76,17 +76,14 @@ jQuery(function()
slug_input.trigger('sluggenerate');
});

if (name_input.val() === '')
// bind onchange slug generation only if starting out with an empty name
name_input.on('change', function()
{
// bind onchange slug generation only if starting out with an empty name
name_input.on('change', function()
if(slug_input.val().length === 0)
{
if(slug_input.val().length === 0)
{
slug_input.trigger('sluggenerate');
}
});
}
slug_input.trigger('sluggenerate');
}
});
}

});
Expand Down
Expand Up @@ -10,7 +10,7 @@ def generate_url
tmp_resource.name = params[:name]
tmp_resource.reasign_slug

render text: tmp_resource.slug
render plain: tmp_resource.slug
end

def content_type_dialog
Expand Down
2 changes: 1 addition & 1 deletion releaf-content/lib/releaf/content/node.rb
Expand Up @@ -225,7 +225,7 @@ def valid_node_content_classes parent_id=nil
validate :validate_parent_node_is_not_self
validate :validate_parent_is_not_descendant
validate :validate_slug
belongs_to :content, polymorphic: true, dependent: :destroy
belongs_to :content, polymorphic: true, dependent: :destroy, required: false
accepts_nested_attributes_for :content

after_save :update_settings_timestamp, unless: :prevent_auto_update_settings_timestamp?
Expand Down
1 change: 0 additions & 1 deletion releaf-content/lib/releaf/content/route.rb
Expand Up @@ -57,7 +57,6 @@ def name( route_options )
# @return [Array] array of Content::Route objects
def self.for(node_class, node_content_class, default_controller)
node_class = node_class.constantize if node_class.is_a? String

Releaf::Content::BuildRouteObjects.call(
node_class: node_class,
node_content_class: node_content_class,
Expand Down
2 changes: 1 addition & 1 deletion releaf-content/releaf-content.gemspec
Expand Up @@ -17,5 +17,5 @@ Gem::Specification.new do |s|
s.add_dependency 'releaf-core', Releaf::VERSION
s.add_dependency 'stringex', '~> 2.6'
s.add_dependency 'awesome_nested_set', '~> 3.1'
s.add_dependency 'deep_cloneable', '~> 2.2.2'
s.add_dependency 'deep_cloneable', '~> 2.3.0'
end
4 changes: 2 additions & 2 deletions releaf-content/spec/features/nodes_services_spec.rb
Expand Up @@ -423,8 +423,8 @@ def expect_different_values original, copy
expect_different_values(original_url, copied_file_urls[key])

[original_url, copied_file_urls[key]].each do |file_url|
visit file_url
expect(page.status_code).to eq 200
tmpfile = download_file(file_url)
expect(Digest::SHA256.file(tmpfile)).to eq(Digest::SHA256.file(dummy_file_path))
end
end

Expand Down
3 changes: 2 additions & 1 deletion releaf-content/spec/features/nodes_spec.rb
Expand Up @@ -284,7 +284,7 @@

open_toolbox_dialog 'Add child', @lv_root, ".view-index .collection li"
within_dialog do
click_link("Text page")
click_link("Text page")
end

fill_in "Slug", with: "some-slug"
Expand All @@ -293,6 +293,7 @@

fill_in "Slug", with: ""
fill_in 'Name', with: "About them"
blur_from "Name"
expect(page).to have_field("Slug", with: "about-them")

# fill text to allow text page save
Expand Down
16 changes: 9 additions & 7 deletions releaf-content/spec/lib/releaf/content/node_spec.rb
@@ -1,6 +1,6 @@
require "rails_helper"

describe Node do
describe Node, type: :model do
class PlainNode < ActiveRecord::Base
include Releaf::Content::Node
self.table_name = "nodes"
Expand All @@ -9,7 +9,7 @@ class PlainNode < ActiveRecord::Base
let(:plain_subject){ PlainNode.new }

it { is_expected.to accept_nested_attributes_for(:content) }
it { is_expected.to belong_to(:content) }
it { is_expected.to belong_to(:content).required(false) }

it "includes Releaf::Content::Node module" do
expect( Node.included_modules ).to include Releaf::Content::Node
Expand All @@ -31,10 +31,12 @@ class PlainNode < ActiveRecord::Base
end
end

describe ".active (scope)" do
describe ":active scope" do
it "returns active nodes" do
expect( Node ).to receive(:where).with(active: true).and_return('foo')
expect( Node.active ).to eq 'foo'
item_1 = create(:node, active: true, locale: "en")
item_2 = create(:node, active: false, locale: "de")
item_3 = create(:node, active: true, locale: "lv")
expect(Node.active).to eq [item_1, item_3]
end
end

Expand Down Expand Up @@ -519,7 +521,7 @@ class PlainNode < ActiveRecord::Base

context "when #prevent_auto_update_settings_timestamp? is false" do
it "is called after save" do
node = FactoryGirl.build(:node)
node = build(:node)
allow( node ).to receive(:prevent_auto_update_settings_timestamp?).and_return(false)
expect( node ).to receive(:update_settings_timestamp).and_call_original
node.save!
Expand All @@ -528,7 +530,7 @@ class PlainNode < ActiveRecord::Base

context "when #prevent_auto_update_settings_timestamp? is true" do
it "is not called after save" do
node = FactoryGirl.build(:node)
node = build(:node)
allow( node ).to receive(:prevent_auto_update_settings_timestamp?).and_return(true)
expect( node ).to_not receive(:update_settings_timestamp)
node.save!
Expand Down
2 changes: 1 addition & 1 deletion releaf-content/spec/lib/releaf/content/route_spec.rb
@@ -1,7 +1,7 @@
require "rails_helper"

describe Releaf::Content::Route do
let(:node_route) { FactoryGirl.build(:node_route, node_class: Node, node_id: 12, locale: "en", path: "/en") }
let(:node_route) { FactoryBot.build(:node_route, node_class: Node, node_id: 12, locale: "en", path: "/en") }


describe ".default_controller" do
Expand Down
3 changes: 2 additions & 1 deletion releaf-content/spec/routing/node_mapper_spec.rb
Expand Up @@ -165,7 +165,8 @@
it "uses the custom path for public website route" do
routes.draw do
node_routes_for(TextPage) do |route|
get 'home_pages#show', path: "#{route.path}/abc/:my_id"
route.path += "/abc/:my_id"
get 'home_pages#show'
end
end

Expand Down
@@ -1,7 +1,7 @@
require 'rails_helper'

describe Releaf::Content::Node::ParentValidator do
let!(:root_node) { FactoryGirl.create(:node, content_type: 'HomePage') }
let!(:root_node) { FactoryBot.create(:node, content_type: 'HomePage') }

class DummyNodeParentValidatorModel < ActiveRecord::Base
acts_as_node
Expand All @@ -25,17 +25,17 @@ class DummyNodeParentValidatorNode < ActiveRecord::Base

context "when parent is valid" do
it "doesn't add error" do
parent = DummyNodeParentValidatorNode.create!( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
child = DummyNodeParentValidatorNode.new( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )

expect( child ).to be_valid
end
end

context "when parent is invalid" do
it "adds error on content_type" do
parent = DummyNodeParentValidatorNode.create!( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller') )
child = DummyNodeParentValidatorNode.new( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller') )
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )

expect( child ).to be_invalid
expect( child.errors[:content_type].size ).to eq(1)
Expand All @@ -46,8 +46,8 @@ class DummyNodeParentValidatorNode < ActiveRecord::Base

context "when content_type is not in child list" do
it "doesn't add error" do
parent = DummyNodeParentValidatorNode.create!( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
child = DummyNodeParentValidatorNode.new( FactoryGirl.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller', parent_id: parent.id) )
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller', parent_id: parent.id) )

expect( child ).to be_valid
end
Expand Down
Expand Up @@ -19,11 +19,11 @@ class DummyRootValidatorNode < ActiveRecord::Base


def create_node *params
DummyRootValidatorNode.create!( FactoryGirl.attributes_for(:node, *params) )
DummyRootValidatorNode.create!( FactoryBot.attributes_for(:node, *params) )
end

def build_node *params
DummyRootValidatorNode.new( FactoryGirl.attributes_for(:node, *params) )
DummyRootValidatorNode.new( FactoryBot.attributes_for(:node, *params) )
end

context "when node is allowed to be root node" do
Expand Down
Expand Up @@ -30,11 +30,11 @@ class DummySinglenessValidatorNode < ActiveRecord::Base


def create_node *params
DummySinglenessValidatorNode.create!( FactoryGirl.attributes_for(:node, *params) )
DummySinglenessValidatorNode.create!( FactoryBot.attributes_for(:node, *params) )
end

def build_node *params
DummySinglenessValidatorNode.new( FactoryGirl.attributes_for(:node, *params) )
DummySinglenessValidatorNode.new( FactoryBot.attributes_for(:node, *params) )
end

let!(:root_node) { create_node(content_type: 'HomePage') }
Expand Down
Expand Up @@ -372,7 +372,7 @@ RemoteValidator.prototype.register_clicked_button = function(button)
v.clicked_button = button;

// when sending form values with FormData, the clicked button value is not included in the data
// (except on Safari, and therefore also on PhantomJS - that's why the tests worked fine even without this).
// (except on Safari).

// since releaf sometimes uses the clicked button value to modify the action on the server side,
// (e.g. for "Save and create another" feature), the value of the clicked button must be appended
Expand Down
Expand Up @@ -12,8 +12,8 @@ jQuery(function(){
var settings = key_or_settings;
if (typeof settings === "string")
{
settings = {};
settings[key_or_settings] = value;
settings = [];
settings.push({key: key_or_settings, value: value});
}

LiteAjax.ajax({ url: settings_path, method: 'POST', data: { "settings": settings}, json: true })
Expand Down
5 changes: 4 additions & 1 deletion releaf-core/app/builders/releaf/builders.rb
Expand Up @@ -29,7 +29,10 @@ def self.constant_defined_at_scope?(mapping, at)
end

def self.constant_name_error?(error_message, mapping)
(error_message =~ /#{mapping}$/).present?
# rails5 have anonymous classes while in production env for error messags
# ex. `Caused by NameError: uninitialized constant #<Class:0x00007fc1b79e8448>::AnotherFormBuilder` instead of
# `Caused by NameError: uninitialized constant Releaf::Builders::AnotherFormBuilder`
(error_message =~ /#{mapping.split("::").last}$/).present?
end

def self.inherited_builder_scopes
Expand Down
Expand Up @@ -73,7 +73,7 @@ def releaf_has_many_association_body(reflector)
attributes = {
class: ["body", "list"]
}
attributes["data"] = {sortable: nil} if reflector.sortable?
attributes["data"] = {sortable: true} if reflector.sortable?

tag(:div, attributes) do
association_collection(reflector).each_with_index.map do |association_object, index|
Expand Down
Expand Up @@ -79,7 +79,7 @@ def relative_page_relationship(offset)
end

def page_url(page_number)
template.url_for( params.merge( page: page_number ))
template.url_for( params.merge( page: page_number ).permit! )
end

def pagination_select
Expand Down
16 changes: 9 additions & 7 deletions releaf-core/app/controllers/releaf/root_controller.rb
Expand Up @@ -13,15 +13,17 @@ def features

# Store settings for menu collapsing and others
def store_settings
if params[:settings].is_a? Hash
params[:settings].each_pair do|key, value|
value = false if value == "false"
value = true if value == "true"
Releaf.application.config.settings_manager.write(controller: self, key: key, value: value)
settings = params.permit(settings: [:key, :value]).to_h.fetch(:settings, nil)
if settings
settings.each do|item|
next if item[:key].nil? || item[:value].nil?
item[:value] = true if item[:value] == "true"
item[:value] = false if item[:value] == "false"
Releaf.application.config.settings_manager.write(controller: self, key: item[:key], value: item[:value])
end
render nothing: true, status: 200
head :ok
else
render nothing: true, status: 422
head :unprocessable_entity
end
end
end

0 comments on commit 8c7b31b

Please sign in to comment.