Skip to content
Closed
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
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Rails:
Enabled: true

AllCops:
TargetRubyVersion: 2.6

Documentation:
Enabled: false

Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

Layout/MultilineMethodCallBraceLayout:
EnforcedStyle: same_line
16 changes: 9 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in active_admin_datetimepicker.gemspec
Expand All @@ -6,16 +8,16 @@ group :test do
default_rails_version = '5.2.1'
default_activeadmin_version = '1.3.1'

gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}"
gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}"
gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}"

gem 'rspec-rails'
gem 'capybara'
gem 'chromedriver-helper'
gem 'coveralls', require: false # Test coverage website. Go to https://coveralls.io
gem 'sass-rails'
gem 'sqlite3'
gem 'launchy'
gem 'database_cleaner'
gem 'capybara'
gem 'launchy'
gem 'rspec-rails'
gem 'sass-rails'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
gem 'sqlite3'
end
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "bundler"
# frozen_string_literal: true

require 'bundler'
require 'rake'
Bundler.setup
Bundler::GemHelper.install_tasks
Expand Down
27 changes: 14 additions & 13 deletions active_admin_datetimepicker.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'active_admin_datetimepicker/version'

Gem::Specification.new do |spec|
spec.name = "active_admin_datetimepicker"
spec.name = 'active_admin_datetimepicker'
spec.version = ActiveAdminDatetimepicker::VERSION
spec.authors = ["Igor Fedoronchuk"]
spec.email = ["[email protected]"]
spec.authors = ['Igor Fedoronchuk']
spec.email = ['[email protected]']

spec.summary = %q{datetimepicker extension for ActiveAdmin}
spec.description = %q{Integrate jQuery xdan datetimepicker plugin to ActiveAdmin}
spec.homepage = "https://github.com/activeadmin-plugins/activeadmin_datetimepicker"
spec.license = "MIT"
spec.summary = 'datetimepicker extension for ActiveAdmin'
spec.description = 'Integrate jQuery xdan datetimepicker plugin to ActiveAdmin'
spec.homepage = 'https://github.com/activeadmin-plugins/activeadmin_datetimepicker'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "bin"
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "activeadmin", "~> 1.1"
spec.add_dependency "xdan-datetimepicker-rails", "~> 2.5.4"
spec.add_dependency 'activeadmin', '~> 1.1'
spec.add_dependency 'xdan-datetimepicker-rails', '~> 2.5.4'
end
2 changes: 2 additions & 0 deletions config/initializers/active_admin_datetimepicker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

ActiveAdmin.setup do |config|
config.register_stylesheet 'jquery.xdan.datetimepicker.css'
end
2 changes: 2 additions & 0 deletions lib/active_admin_datetimepicker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'activeadmin'
require 'xdan-datetimepicker-rails'
require 'active_admin_datetimepicker/version'
Expand Down
24 changes: 18 additions & 6 deletions lib/active_admin_datetimepicker/base.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# frozen_string_literal: true

module ActiveAdminDatetimepicker
module Base
mattr_accessor :default_datetime_picker_options
@@default_datetime_picker_options = {}
mattr_accessor :format
@@format = '%Y-%m-%d %H:%M'
@@format = '%Y/%m/%d %H:%M'
mattr_accessor :format_date
@@format_date = '%Y/%m/%d'
# mattr_accessor :format_time
# @@format_time = '%H:%M'

def html_class
'date-time-picker'
Expand All @@ -13,20 +19,27 @@ def input_html_data
{}
end

def input_html_options(input_name = nil, placeholder = nil)
def input_html_options(input_name = nil, _placeholder = nil)
options = {}
options[:class] = [self.options[:class], html_class].compact.join(' ')
options[:data] ||= input_html_data
options[:data].merge!(datepicker_options: datetime_picker_options)
options[:data][:datepicker_options] = datetime_picker_options
options[:value] ||= input_value(input_name)
options[:maxlength] = 19
options
end

def input_value(input_name = nil)
val = object.public_send(input_name || method)
return DateTime.new(val.year, val.month, val.day, val.hour, val.min, val.sec).strftime(format) if val.is_a?(Time)
val.to_s
case val
when Time
return DateTime.new(val.year, val.month, val.day, val.hour, val.min,
val.sec).strftime(format)
when Date
return Date.new(val.year, val.month, val.day).strftime(format_date)
else
val.to_s
end
end

def datetime_picker_options
Expand All @@ -53,4 +66,3 @@ def _default_datetime_picker_options
end
end
end

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActiveAdmin
module Inputs
class DateTimePickerInput < ::Formtastic::Inputs::StringInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActiveAdmin
module Inputs
module Filters
Expand Down
4 changes: 3 additions & 1 deletion lib/active_admin_datetimepicker/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActiveAdminDatetimepicker
VERSION = '0.6.3'
VERSION = '0.6.4'
end
4 changes: 2 additions & 2 deletions spec/active_admin_datetimepicker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'

describe ActiveAdminDatetimepicker do

it 'has a version number' do
expect(ActiveAdminDatetimepicker::VERSION).not_to be nil
end

end
6 changes: 3 additions & 3 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'

describe ActiveAdminDatetimepicker::Base do

class Dummy
include ActiveAdminDatetimepicker::Base
end

let(:dummy) { Dummy.new }

it 'html_class' do
expect(dummy.html_class).to eq "date-time-picker"
expect(dummy.html_class).to eq 'date-time-picker'
end

it 'format' do
expect(dummy.format).to eq '%Y-%m-%d %H:%M'
expect(ActiveAdminDatetimepicker::Base.format).to eq '%Y-%m-%d %H:%M'
end

end
6 changes: 3 additions & 3 deletions spec/date_time_picker_input_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

require 'spec_helper'

describe ActiveAdmin::Inputs::DateTimePickerInput do

it 'included from ActiveAdminDatetimepicker::Base' do
input = ActiveAdmin::Inputs::DateTimePickerInput.new(
# all dummy args for now
Object.new, Object.new, Object.new, Object.new, Object.new, {})
expect(input.html_class).to eq "date-time-picker"
expect(input.html_class).to eq 'date-time-picker'
expect(input.format).to eq '%Y-%m-%d %H:%M'
end

end
17 changes: 8 additions & 9 deletions spec/filters_and_edit_form_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'authors index', type: :feature, js: true do

before do
Author.create!(name: "John", last_name: "Doe")
Author.create!(name: "Jane", last_name: "Roe")
Author.create!(name: 'John', last_name: 'Doe')
Author.create!(name: 'Jane', last_name: 'Roe')
end

before do
Expand Down Expand Up @@ -33,15 +34,14 @@
end

it 'can set date from/to' do
date_from = Date.today.beginning_of_month.strftime("%Y-%m-%d")
date_to = (Date.today.beginning_of_month + 19.days).strftime("%Y-%m-%d")
date_from = Date.today.beginning_of_month.strftime('%Y-%m-%d')
date_to = (Date.today.beginning_of_month + 19.days).strftime('%Y-%m-%d')

expect(page.find('input#q_birthday_gteq').value).to start_with(date_from)
expect(page.find('input#q_birthday_lteq').value).to start_with(date_to)
end
end


context 'edit form' do
before do
visit '/admin/authors/new'
Expand All @@ -56,10 +56,9 @@
.find('.xdsoft_timepicker.active .xdsoft_time.xdsoft_current').click
end

it 'can set birthday' do
date_birthday = Date.today.beginning_of_month.strftime("%Y-%m-%d")
it 'can set birthday' do
date_birthday = Date.today.beginning_of_month.strftime('%Y-%m-%d')
expect(page.find('#author_birthday').value).to start_with(date_birthday)
end
end

end
14 changes: 7 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'coveralls'
Coveralls.wear!

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH << File.expand_path('../support', __FILE__)
$LOAD_PATH << File.expand_path('support', __dir__)

ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
require "bundler"
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __dir__)
require 'bundler'
Bundler.setup

ENV['RAILS_ENV'] = 'test'
Expand All @@ -14,15 +16,13 @@
ENV['RAILS'] = Rails.version
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
# Create the test app if it doesn't exists
unless File.exists?(ENV['RAILS_ROOT'])
system 'rake setup'
end
system 'rake setup' unless File.exist?(ENV['RAILS_ROOT'])

require 'active_model'
# require ActiveRecord to ensure that Ransack loads correctly
require 'active_record'
require 'active_admin'
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"]
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + '/app/admin']
require ENV['RAILS_ROOT'] + '/config/environment.rb'
# Disabling authentication in specs so that we don't have to worry about
# it allover the place
Expand Down
4 changes: 2 additions & 2 deletions spec/support/admin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def add_author_resource(options = {}, &block)
# frozen_string_literal: true

def add_author_resource(_options = {})
ActiveAdmin.register Author do
config.filters = true

Expand All @@ -17,5 +18,4 @@ def add_author_resource(options = {}, &block)
end
end
Rails.application.reload_routes!

end
5 changes: 3 additions & 2 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Capybara.server = :webrick

Capybara.configure do |config|
Expand All @@ -6,8 +8,7 @@

Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(
args: %w[headless disable-gpu no-sandbox]
)
args: %w[headless disable-gpu no-sandbox])
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Expand Down
24 changes: 13 additions & 11 deletions spec/support/rails_template.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# frozen_string_literal: true

# Rails template to build the sample app for specs

generate :model, 'author name:string{10}:uniq last_name:string birthday:date'
generate :model, 'post title:string:uniq body:text author:references'

#Add validation
inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "Base\n"
inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n"
# Add validation
inject_into_file 'app/models/author.rb', " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "Base\n"
inject_into_file 'app/models/post.rb', " validates_presence_of :author\n", after: ":author\n"

# Configure default_url_options in test environment
inject_into_file "config/environments/test.rb", " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n"
inject_into_file 'config/environments/test.rb', " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n"

# Add our local Active Admin to the load path
inject_into_file "config/environment.rb",
inject_into_file 'config/environment.rb',
"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n",
after: "require File.expand_path('../application', __FILE__)"

run "rm Gemfile"
run 'rm Gemfile'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

generate :'active_admin:install --skip-users'
generate :'formtastic:install'

# Install active_admin_date_time_datetimepicker assets
inject_into_file "app/assets/stylesheets/active_admin.scss",
inject_into_file 'app/assets/stylesheets/active_admin.scss',
"@import \"active_admin_datetimepicker\";\n",
after: "@import \"active_admin/base\";\n"

inject_into_file "app/assets/javascripts/active_admin.js.coffee",
inject_into_file 'app/assets/javascripts/active_admin.js.coffee',
"#= require active_admin_datetimepicker\n",
after: "#= require active_admin/base\n"

run "rm -r test"
run "rm -r spec"
run 'rm -r test'
run 'rm -r spec'

route "root :to => 'admin/dashboard#index'"

rake "db:migrate"
rake 'db:migrate'
Loading