forked from spree-contrib/spree_slider
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spree-contrib#50 from TruemarkDev/spree_4_fix
Spree 4 migration
- Loading branch information
Showing
40 changed files
with
563 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ spec/dummy | |
pkg/* | ||
Gemfile.lock | ||
gemfiles/*.gemfile.lock | ||
|
||
coverage | ||
.byebug_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
--colour | ||
--color | ||
-r spec_helper | ||
-f documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,46 @@ | ||
sudo: required | ||
dist: trusty | ||
os: linux | ||
dist: bionic | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- google-chrome | ||
packages: | ||
- google-chrome-stable | ||
|
||
services: | ||
- mysql | ||
- postgresql | ||
|
||
language: ruby | ||
|
||
rvm: | ||
- 2.6 | ||
|
||
env: | ||
- DB=postgres | ||
- DB=mysql | ||
- DB=postgres | ||
|
||
gemfile: | ||
- gemfiles/spree_3_1.gemfile | ||
- gemfiles/spree_3_2.gemfile | ||
- gemfiles/spree_3_7.gemfile | ||
- gemfiles/spree_4_0.gemfile | ||
- gemfiles/spree_4_1.gemfile | ||
- gemfiles/spree_master.gemfile | ||
|
||
script: | ||
- bundle exec rspec spec | ||
jobs: | ||
allow_failures: | ||
- gemfile: gemfiles/spree_master.gemfile | ||
|
||
rvm: | ||
- 2.3.1 | ||
- 2.2.7 | ||
before_script: | ||
- CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'` | ||
- CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"` | ||
- curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O | ||
- unzip chromedriver_linux64.zip -d ~/bin | ||
- nvm install 14 | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- mysql-server-5.6 | ||
- mysql-client-core-5.6 | ||
- mysql-client-5.6 | ||
script: | ||
- bundle exec rake test_app | ||
- bundle exec rake spec | ||
|
||
before_install: | ||
- mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
source 'http://rubygems.org' | ||
|
||
source 'https://rubygems.org' | ||
|
||
spree_version = 'master' | ||
gem 'spree', github: 'spree/spree', branch: spree_version | ||
spree_version = '~> 4.0' | ||
gem 'spree', spree_version | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
require "bundler/gem_tasks" | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rspec/core/rake_task' | ||
require 'spree/testing_support/extension_rake' | ||
|
||
RSpec::Core::RakeTask.new | ||
Rake::Task.define_task(:environment) | ||
|
||
task default: :environment do | ||
if Dir['spec/dummy'].empty? | ||
Rake::Task[:test_app].invoke | ||
Dir.chdir('../../') | ||
end | ||
Rake::Task[:spec].invoke | ||
end | ||
|
||
desc 'Generates a dummy app for testing' | ||
task test_app: :environment do | ||
ENV['LIB_NAME'] = 'spree_slider' | ||
Rake::Task['extension:test_app'].invoke | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Spree | ||
module Admin | ||
module SlidesHelper | ||
def get_column_header_by_type(type) | ||
return Spree.t(:name) if type == :image | ||
return Spree.t(:product) if type == :product | ||
|
||
return '----' | ||
end | ||
|
||
def get_image_link_by_type(slide, type) | ||
return link_to(slide.name, object_url(slide)) if type == :image | ||
return link_to(slide.product.name, object_url(slide)) if type == :product && slide.product | ||
|
||
return '----' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
Spree::Product.class_eval do | ||
has_one :slide, dependent: :destroy | ||
after_update :destroy_slide_if_deleted | ||
module Spree | ||
module ProductDecorator | ||
def self.prepended(base) | ||
base.has_one :slide | ||
base.after_destroy :destroy_slide_if_deleted | ||
end | ||
|
||
def destroy_slide_if_deleted | ||
slide.update_attributes(published: false) if slide && deleted_at | ||
def destroy_slide_if_deleted | ||
slide.update(published: false) if slide && deleted_at | ||
end | ||
end | ||
end | ||
|
||
::Spree::Product.prepend(Spree::ProductDecorator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
class Spree::SlideLocation < ActiveRecord::Base | ||
|
||
has_and_belongs_to_many :slides, | ||
class_name: 'Spree::Slide', | ||
join_table: 'spree_slide_slide_locations' | ||
|
||
validates :name, presence: true | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class UrlValidator < ActiveModel::EachValidator | ||
|
||
def validate_each(record, attribute, value) | ||
uri = parse_uri(value) | ||
if !uri | ||
record.errors[attribute] << generic_failure_message | ||
elsif !allowed_protocols.include?(uri.scheme) | ||
record.errors[attribute] << "must begin with #{allowed_protocols_humanized}" | ||
end | ||
end | ||
|
||
private | ||
|
||
def generic_failure_message | ||
options[:message] || "is an invalid URL" | ||
end | ||
|
||
def allowed_protocols_humanized | ||
allowed_protocols.to_sentence(:two_words_connector => ' or ') | ||
end | ||
|
||
def allowed_protocols | ||
@allowed_protocols ||= [(options[:allowed_protocols] || ['http', 'https'])].flatten | ||
end | ||
|
||
def parse_uri(value) | ||
uri = Addressable::URI.parse(value) | ||
uri.scheme && uri.host && uri | ||
rescue URI::InvalidURIError, Addressable::URI::InvalidURIError, TypeError | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.