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 to support Refinery CMS 4.0.3+ #170

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
language: ruby
cache: bundler
sudo: false
addons:
postgresql: '10'
services:
- mysql
branches:
only:
- master
bundler_args: --without development
before_script: "bin/rake refinery:testing:dummy_app"
script: "bin/rspec spec"
notifications:
email: true
irc:
use_notice: true
skip_join: true
channels:
- "irc.freenode.org#refinerycms"
campfire:
on_success: always
on_failure: always
rooms:
- secure: "JaX+Ckvdd2wqL2bD6t8PHvMDBHxWBlCrkBKPcDKxV0t0DOwzzzwxMryVqcRi\nPsmM/zvmWFATDyRmivhNOpu4lRg9RytSroxZ9nkmbLDqjCyEAZ6tv4yZXME/\nPaxPwmfwgS9g8TKjj3lSWS7rEpqqg0D5S0XIfIHrj6KB6LUmFHc="
webhooks:
- https://webhooks.gitter.im/e/b5d48907cdc89864b874
env:
- DB=postgresql
- DB=mysql
rvm:
- 2.2
- 2.1
- 2.0.0
- 2.6
19 changes: 12 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ source "https://rubygems.org"

gemspec

git "https://github.com/refinery/refinerycms", branch: "master" do
gem 'refinerycms'
gem 'refinerycms', '~> 4.0.3'

group :development, :test do
gem 'refinerycms-testing'
end
group :development, :test do
gem 'refinerycms-testing', '~> 4.0.3'
gem 'listen'
end

group :test do
Expand All @@ -16,6 +15,12 @@ group :test do
gem 'selenium-webdriver'
end

# Add support for refinerycms-acts-as-indexed
gem 'refinerycms-acts-as-indexed', ['~> 3.0', '>= 3.0.0']

# Add the default visual editor, for now.
gem 'refinerycms-wymeditor', ['~> 2.2', '>= 2.2.0']

# Database Configuration
unless ENV['TRAVIS']
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
Expand All @@ -40,6 +45,6 @@ group :assets do
end

# Load local gems according to Refinery developer preference.
if File.exist? local_gemfile = File.expand_path('../.gemfile', __FILE__)
eval File.read(local_gemfile)
if File.exist?(local_gemfile = File.expand_path('../.gemfile', __FILE__))
eval_gemfile local_gemfile
end
6 changes: 3 additions & 3 deletions app/controllers/refinery/news/items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Refinery
module News
class ItemsController < ::ApplicationController
before_filter :find_page
before_filter :find_published_news_items, :only => [:index]
before_filter :find_news_item, :find_latest_news_items, :only => [:show]
before_action :find_page
before_action :find_published_news_items, :only => [:index]
before_action :find_news_item, :find_latest_news_items, :only => [:show]

def index
# render 'index'
Expand Down
8 changes: 4 additions & 4 deletions app/models/refinery/news/item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'acts_as_indexed'
require 'globalize'
require 'mobility'

module Refinery
module News
Expand All @@ -18,11 +18,11 @@ class Item < Refinery::Core::BaseModel

default_scope proc { order "publish_date DESC" }

friendly_id :title, :use => [:slugged, :globalize]
friendly_id :title, :use => [:slugged, :mobility]

# If title changes tell friendly_id to regenerate slug when saving record
def should_generate_new_friendly_id?
title_changed?
attribute_changed?(:title)
end

def not_published? # has the published date not yet arrived?
Expand Down Expand Up @@ -83,7 +83,7 @@ def archived
# rejects any page that has not been translated to the current locale.
def translated
includes(:translations).where(
translation_class.arel_table[:locale].eq(::Globalize.locale)
translation_class.arel_table[:locale].eq(::Mobility.locale)
).where(
arel_table[:id].eq(translation_class.arel_table[:refinery_news_item_id])
).references(:translations)
Expand Down
4 changes: 2 additions & 2 deletions app/views/refinery/news/admin/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:object => @item,
:include_object_name => true %>

<%= render '/refinery/admin/locale_picker', :current_locale => Globalize.locale %>
<%= render '/refinery/admin/locale_picker', :current_locale => Mobility.locale %>

<div class='field'>
<%= f.label :title %>
Expand All @@ -23,7 +23,7 @@

<div class='field'>
<%= f.label :body %>
<%= f.text_area :body, :rows => "20", :class => "wymeditor widest" %>
<%= f.text_area :body, :rows => "20", :class => "visual_editor widest" %>
</div>

<div class='field'>
Expand Down
22 changes: 9 additions & 13 deletions app/views/refinery/news/admin/items/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
(locales = item.translations.collect{|t| t.locale}).present? %>
<span class='preview'>
<% locales.each do |locale| %>
<%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '16x11'), refinery.edit_news_admin_item_path(item, :switch_locale => locale),
<%= link_to refinery_icon_tag("flags/#{locale}", :size => '16x11'), refinery.edit_news_admin_item_path(item, :switch_locale => locale),
:class => "locale" %>
<% end %>
</span>
<% end %>
</span>
<span class='actions'>
<%= link_to refinery_icon_tag('application_go.png'), refinery.news_item_path(item),
:title => t('.view_live_html'),
:target => "_blank" %>
<%= link_to refinery_icon_tag('application_edit.png'), refinery.edit_news_admin_item_path(item),
:title => t('.edit') %>
<%= link_to refinery_icon_tag('delete.png'), refinery.news_admin_item_path(item),
:class => "cancel confirm-delete",
:title => t('.delete'),
:method => :delete,
:data => {
:confirm => t('refinery.admin.delete.message', :title => item.title)
} %>
<%= action_icon 'go', refinery.news_item_path(item), t('.view_live_html'), target: "_blank" %>
<%= action_icon 'edit', refinery.edit_news_admin_item_path(item), t('.edit') %>
<%= action_icon 'delete', refinery.news_admin_item_path(item), t('.delete'),
class: "cancel confirm-delete",
method: :delete,
data: {
confirm: t('refinery.admin.delete.message', :title => item.title)
} %>
</span>
</li>
2 changes: 1 addition & 1 deletion db/migrate/20110817203701_create_news_items.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateNewsItems < ActiveRecord::Migration
class CreateNewsItems < ActiveRecord::Migration[4.2]

def up
create_table ::Refinery::News::Item.table_name do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddExternalUrlToNewsItems < ActiveRecord::Migration
class AddExternalUrlToNewsItems < ActiveRecord::Migration[4.2]

def up
unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20110817203703_translate_news_items.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TranslateNewsItems < ActiveRecord::Migration
class TranslateNewsItems < ActiveRecord::Migration[4.2]

def up
::Refinery::News::Item.reset_column_information
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20110817203704_add_image_id_to_news_items.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddImageIdToNewsItems < ActiveRecord::Migration
class AddImageIdToNewsItems < ActiveRecord::Migration[4.2]

def up
unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:image_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddExpirationDateToNewsItems < ActiveRecord::Migration
class AddExpirationDateToNewsItems < ActiveRecord::Migration[4.2]

def up
unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:expiration_date)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RemoveImageIdAndExternalUrlFromNews < ActiveRecord::Migration
class RemoveImageIdAndExternalUrlFromNews < ActiveRecord::Migration[4.2]
def up
if ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url)
remove_column ::Refinery::News::Item.table_name, :external_url
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20120129230838_add_source_to_news_items.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This migration comes from refinery_news (originally 7)
class AddSourceToNewsItems < ActiveRecord::Migration
class AddSourceToNewsItems < ActiveRecord::Migration[4.2]

def up
unless Refinery::News::Item.column_names.map(&:to_sym).include?(:source)
Expand All @@ -13,4 +13,4 @@ def down
end
end

end
end
4 changes: 2 additions & 2 deletions db/migrate/20120129230839_translate_source.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This migration comes from refinery_news (originally 8)
class TranslateSource < ActiveRecord::Migration
class TranslateSource < ActiveRecord::Migration[4.2]

def up
unless Refinery::News::Item::Translation.column_names.map(&:to_sym).include?(:source)
Expand All @@ -13,4 +13,4 @@ def down
end
end

end
end
2 changes: 1 addition & 1 deletion db/migrate/20120228150250_add_slug_to_news_items.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddSlugToNewsItems < ActiveRecord::Migration
class AddSlugToNewsItems < ActiveRecord::Migration[4.2]
def change
add_column Refinery::News::Item.table_name, :slug, :string
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MoveSlugToNewsItemTranslations < ActiveRecord::Migration
class MoveSlugToNewsItemTranslations < ActiveRecord::Migration[4.2]
def up
# Fix index problem if this is rolled back
remove_index Refinery::News::Item.translation_class.table_name, :refinery_news_item_id
Expand Down
15 changes: 9 additions & 6 deletions refinerycms-news.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Encoding: UTF-8
require 'date'

Gem::Specification.new do |s|
s.name = %q{refinerycms-news}
s.version = %q{3.0.0}
s.version = %q{4.0.0}
s.description = %q{A really straightforward open source Ruby on Rails news engine designed for integration with Refinery CMS.}
s.summary = %q{Ruby on Rails news engine for Refinery CMS.}
s.email = %q{info@refinerycms.com}
Expand All @@ -13,9 +14,11 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'refinerycms-core', '~> 3.0.0'
s.add_dependency 'refinerycms-settings', '~> 3.0.0'
s.add_dependency 'friendly_id', ['~> 5.1', '< 5.3']
s.add_dependency 'globalize', ['>= 4.0.0', '< 5.2']
s.add_dependency 'acts_as_indexed', '~> 0.8.0'
s.add_dependency 'refinerycms-core', '~> 4.0.3'
s.add_dependency 'refinerycms-settings', '~> 4.0.1'
s.add_dependency 'friendly_id', '~> 5.2.1'
s.add_dependency 'friendly_id-mobility', '~> 0.5'

# Development dependencies
s.add_development_dependency 'refinerycms-testing', '~> 4.0.3'
end
14 changes: 7 additions & 7 deletions spec/controllers/refinery/news/items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Refinery
module News
describe ItemsController, :type => :controller do
let!(:item) { FactoryGirl.create(:news_item) }
let!(:item) { FactoryBot.create(:news_item) }
let(:refinery_page) { Refinery::Page.where(:link_url => "/news").first }

describe "#index" do
Expand All @@ -21,13 +21,13 @@ module News

describe "#show" do
it "assigns item and page" do
get :show, :id => item.id
get :show, params: { id: item.id }
expect(assigns(:item)).to eq(item)
expect(assigns(:page)).to eq(refinery_page)
end

it "renders 'show' template" do
get :show, :id => item.id
get :show, params: { id: item.id }
expect(response).to render_template(:show)
end
end
Expand All @@ -36,7 +36,7 @@ module News
context "when month is present" do
it "assigns archive_date and items" do
allow(Refinery::News::Item).to receive_message_chain(:archived, :translated, :by_archive, :page).and_return(item)
get :archive, :month => 05, :year => 1999
get :archive, params: { month: 05, year: 1999 }
expect(assigns(:archive_date)).to eq(Time.parse("05/1999"))
expect(assigns(:items)).to eq(item)
expect(assigns(:archive_for_month)).to be_truthy
Expand All @@ -46,19 +46,19 @@ module News
context "when month isnt present" do
it "assigns archive_date and items" do
allow(Refinery::News::Item).to receive_message_chain(:archived, :translated, :by_year, :page).and_return(item)
get :archive, :year => 1999
get :archive, params: { year: 1999 }
expect(assigns(:archive_date)).to eq(Time.parse("01/1999"))
expect(assigns(:items)).to eq(item)
end
end

it "renders 'archive' template" do
get :archive, :year => 1999
get :archive, params: { year: 1999 }
expect(response).to render_template(:archive)
end

it "assigns page" do
get :archive, :year => 1999
get :archive, params: { year: 1999 }
expect(assigns(:page)).to eq(refinery_page)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/news.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :news_item, :class => Refinery::News::Item do
title "Refinery CMS News Item"
content "Some random text ..."
Expand Down
6 changes: 3 additions & 3 deletions spec/features/manage_news_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

describe "edit/update" do
before { FactoryGirl.create(:news_item, :title => "Update me") }
before { FactoryBot.create(:news_item, :title => "Update me") }

it "updates news item" do
visit refinery.news_admin_items_path
Expand All @@ -61,7 +61,7 @@
end

describe "destroy" do
before { FactoryGirl.create(:news_item, :title => "Delete me") }
before { FactoryBot.create(:news_item, :title => "Delete me") }

it "removes news item" do
visit refinery.news_admin_items_path
Expand All @@ -75,7 +75,7 @@
end

context "duplicate news item titles" do
before { FactoryGirl.create(:news_item, :title => "I was here first") }
before { FactoryBot.create(:news_item, :title => "I was here first") }

it "isn't a problem" do
visit refinery.new_news_admin_item_path
Expand Down
8 changes: 4 additions & 4 deletions spec/features/visit_news_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

describe "visit news items", :type => :feature do
before do
FactoryGirl.create(:page, :link_url => "/")
FactoryGirl.create(:page, :link_url => "/news", :title => "News")
FactoryGirl.create(:news_item, :title => "unpublished", :publish_date => 1.day.from_now)
@published_news_item = FactoryGirl.create(:news_item, :title => "published", :source => "http://refinerycms.com", :publish_date => 1.hour.ago)
FactoryBot.create(:page, :link_url => "/")
FactoryBot.create(:page, :link_url => "/news", :title => "News")
FactoryBot.create(:news_item, :title => "unpublished", :publish_date => 1.day.from_now)
@published_news_item = FactoryBot.create(:news_item, :title => "published", :source => "http://refinerycms.com", :publish_date => 1.hour.ago)
end

it "shows news link in menu" do
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/refinery/news/items_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module News
describe ItemsHelper, :type => :helper do
describe '#news_item_archive_links' do
before do
2.times { FactoryGirl.create(:news_item, :publish_date => Time.utc(2012, 05)) }
3.times { FactoryGirl.create(:news_item, :publish_date => Time.utc(2012, 04)) }
2.times { FactoryBot.create(:news_item, :publish_date => Time.utc(2012, 05)) }
3.times { FactoryBot.create(:news_item, :publish_date => Time.utc(2012, 04)) }
end

it 'returns list of links to archives' do
Expand Down
Loading