Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gutentag #1386

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alchemy_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'coffee-rails', ['~> 4.0']
gem.add_runtime_dependency 'dragonfly', ['~> 1.0', '>= 1.0.7']
gem.add_runtime_dependency 'dragonfly_svg', ['~> 0.0.4']
gem.add_runtime_dependency 'gutentag', ['~> 2.1.0']
gem.add_runtime_dependency 'gutentag', ['~> 2.2', '>= 2.2.1']
gem.add_runtime_dependency 'handlebars_assets', ['~> 0.23']
gem.add_runtime_dependency 'jquery-rails', ['~> 4.0', '>= 4.0.4']
gem.add_runtime_dependency 'jquery-ui-rails', ['~> 5.0.0']
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/app/controllers/admin/locations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Admin::LocationsController < Alchemy::Admin::ResourcesController

end
3 changes: 2 additions & 1 deletion spec/dummy/app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Ability
def initialize(user)
can :manage, Event
can :index, :admin_events
can :manage, Location
can :index, :admin_locations
end

end
9 changes: 9 additions & 0 deletions spec/dummy/app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
class Event < ActiveRecord::Base
include Alchemy::Taggable

validates_presence_of :name
belongs_to :location

scope :starting_today, -> { where(starts_at: Time.current.at_midnight..Date.tomorrow.at_midnight) }
scope :future, -> { where("starts_at > ?", Date.tomorrow.at_midnight) }

def self.alchemy_resource_relations
{
location: {attr_method: 'name', attr_type: 'string'}
}
end

def self.alchemy_resource_filters
%w(starting_today future)
end
end
1 change: 1 addition & 0 deletions spec/dummy/app/models/location.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Location < ActiveRecord::Base
include Alchemy::Taggable
has_many :events
end
18 changes: 18 additions & 0 deletions spec/dummy/config/initializers/alchemy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Alchemy.register_ability Ability
Alchemy.user_class_name = 'DummyUser'
Alchemy.signup_path = '/admin/pages' unless Rails.env.test?
Alchemy::Modules.register_module(
name: 'events',
navigation: {
name: 'Events',
controller: '/admin/events',
action: 'index',
icon: 'calendar-alt',
sub_navigation: [{
name: 'Events',
controller: '/admin/events',
action: 'index'
}, {
name: 'Locations',
controller: '/admin/locations',
action: 'index'
}]
}
)
11 changes: 11 additions & 0 deletions spec/dummy/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ en:
essence_richtext: This content type (Essence) represents richtext
essence_select: This content type (Essence) represents values the editor can choose from
essence_text: This content type (Essence) represents a simple line of text

activerecord:
models:
event:
one: Event
other: Events
attributes:
event:
tag_names: Tags
location:
tag_names: Tags
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace :admin do
resources :events
resources :locations
end

mount Alchemy::Engine => "/"
Expand Down
18 changes: 6 additions & 12 deletions spec/features/admin/modules_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
before { authorize_user(:as_admin) }

it "should have a button in main_navigation, pointing to the configured controller" do
Alchemy::Modules.register_module(
{
name: 'events',
navigation: {
icon: 'icon events',
name: 'Events',
controller: '/admin/events',
action: 'index'
}
})
visit '/admin'
click_on 'Events'
expect(page).not_to have_content('Upps!')
within '#main_navi' do
first('a', text: 'Events').click
end
within '#main_content' do
expect(page).to have_content('0 Events')
end
end
end
end
24 changes: 0 additions & 24 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require 'spec_helper'

def reload_event_class
Object.send(:remove_const, :Event)
load "spec/dummy/app/models/event.rb"
end

describe "Resources" do
let(:event) { create(:event) }
let(:second_event) { create(:event, name: 'My second Event', entrance_fee: 12.32) }
Expand Down Expand Up @@ -135,12 +130,6 @@ def reload_event_class
end

context "with event that acts_as_taggable" do
around do |example|
Event.class_eval { include Alchemy::Taggable }
example.run
reload_event_class
end

it "shows an autocomplete tag list in the form" do
visit "/admin/events/new"
expect(page).to have_selector('input#event_tag_list[type="text"][data-autocomplete="/admin/tags/autocomplete"]')
Expand Down Expand Up @@ -174,19 +163,6 @@ def reload_event_class
end

context "with event that has filters defined" do
around do |example|
Event.class_eval do
def self.alchemy_resource_filters
%w(starting_today future)
end

scope :starting_today, -> { where(starts_at: Time.current.at_midnight..Date.tomorrow.at_midnight) }
scope :future, -> { where("starts_at > ?", Date.tomorrow.at_midnight) }
end
example.run
reload_event_class
end

let!(:past_event) { create(:event, name: "Horse Expo", starts_at: Time.current - 100.years) }
let!(:today_event) { create(:event, name: "Car Expo", starts_at: Time.current.at_noon) }
let!(:future_event) { create(:event, name: "Hovercar Expo", starts_at: Time.current + 30.years) }
Expand Down
2 changes: 1 addition & 1 deletion spec/libraries/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ module Alchemy

describe '#model_association_names' do
it 'returns an array of association names' do
expect(resource.model_association_names).to eq [:location]
expect(resource.model_association_names).to include(:location)
end
end

Expand Down