Skip to content

Commit 6b2fee9

Browse files
Run rubocop
1 parent 91bc86e commit 6b2fee9

36 files changed

+64
-106
lines changed

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Naming/PredicateName:
7171
AllowedMethods:
7272
- has_many
7373
- has_many_actions
74+
- is_association?
7475

7576
Style/TrailingCommaInArguments:
7677
Enabled: true

activeadmin-mongoid.gemspec

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
43
require 'active_admin/mongoid/version'
54

@@ -10,7 +9,7 @@ Gem::Specification.new do |gem|
109
gem.summary = %q{ActiveAdmin hacks to support Mongoid}
1110
gem.homepage = ''
1211

13-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
1413
gem.files = `git ls-files`.split("\n")
1514
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
1615
gem.name = 'activeadmin-mongoid'
@@ -24,7 +23,7 @@ Gem::Specification.new do |gem|
2423
gem.add_runtime_dependency 'activeadmin', '>= 1.4.3'
2524
gem.add_runtime_dependency 'kaminari-mongoid'
2625
gem.add_runtime_dependency 'jquery-rails'
27-
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4']
26+
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4']
2827

29-
gem.add_development_dependency 'rspec-rails', '~> 3.6'
28+
gem.add_development_dependency 'rspec-rails', '~> 3.6'
3029
end

lib/active_admin/mongoid/association/relatable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def foreign_key
1111
return if embeds?
1212
foreign_key.to_sym rescue nil
1313
end
14-
end
14+
end

lib/active_admin/mongoid/controllers/resource_controller.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'active_admin/engine'
22

33
ActiveAdmin::Engine.module_eval do
4-
54
initializer 'active_admin.mongoid.resource_controller' do
65
class ActiveAdmin::ResourceController
76
def build_new_resource

lib/active_admin/mongoid/criteria.rb

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ def from(*a)
1919
end
2020
end
2121
end
22-

lib/active_admin/mongoid/csv_builder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def build(controller, csv)
1111
csv << bom if bom
1212

1313
if column_names
14-
csv << CSV.generate_line(columns.map{ |c| encode c.name, options }, csv_options)
14+
csv << CSV.generate_line(columns.map { |c| encode c.name, options }, csv_options)
1515
end
1616

1717
(1..paginated_collection.total_pages).each do |page|

lib/active_admin/mongoid/document.rb

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
module ActiveAdmin::Mongoid::Document
44
extend ActiveSupport::Concern
55

6-
7-
8-
96
# PROXY CLASSES
107

118
class ColumnWrapper < SimpleDelegator
@@ -30,9 +27,6 @@ def quote_column_name name
3027
end
3128
end
3229

33-
34-
35-
3630
# CLASS METHODS
3731

3832
included do
@@ -47,7 +41,6 @@ class << self
4741
def column_for_attribute(name)
4842
self.class.fields[name.to_sym]
4943
end
50-
5144
end
5245

5346
module ClassMethods
@@ -63,7 +56,7 @@ def connection
6356
end
6457

6558
def find_by_id id
66-
find_by(:_id => id)
59+
find_by(_id: id)
6760
end
6861

6962
def quoted_table_name
@@ -74,7 +67,6 @@ def associations
7467
@associations ||= new.associations
7568
end
7669

77-
7870
def reflections *a
7971
relations *a
8072
end

lib/active_admin/mongoid/filter_form_builder.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def filter(method, options = {})
99
def default_input_type(method, options = {})
1010
if column = column_for(method)
1111
case column.type.name.downcase.to_sym
12-
when :date, :datetime, :time; :date_range
13-
when :string, :text, :object; :string
14-
when :float, :decimal; :numeric
12+
when :date, :datetime, :time; :date_range
13+
when :string, :text, :object; :string
14+
when :float, :decimal; :numeric
1515
when :integer
16-
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
16+
return :select if reflection_for(method.to_s.gsub('_id', '').to_sym)
1717
return :numeric
1818
end
1919
elsif is_association?(method)

lib/active_admin/mongoid/filters/resource_extension.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ActiveAdmin::Filters::ResourceExtension
44
def default_association_filters
55
if resource_class.respond_to?(:reflect_on_all_associations)
66
without_embedded = resource_class.reflect_on_all_associations.reject { |e| e.embeds? }
7-
poly, not_poly = without_embedded.partition{ |r| r.macro == :belongs_to && r.options[:polymorphic] }
7+
poly, not_poly = without_embedded.partition { |r| r.macro == :belongs_to && r.options[:polymorphic] }
88

99
filters = poly.map(&:foreign_key) + not_poly.map(&:name)
1010
filters.map &:to_sym

lib/active_admin/mongoid/resource.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Resource
66
# another. I'm not going to investigate any deeper, let's just remove the
77
# underscore prefixed fields as was the prior behavior
88
def default_filters
9-
super.reject { |filter| filter == :_id }
9+
super.reject { |filter| filter == :_id }
1010
end
1111

1212
module Attributes

lib/active_admin/mongoid/resource/attributes.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Resource
66
module Attributes
77
def foreign_methods
88
@foreign_methods ||= resource_class.reflect_on_all_associations.
9-
select{ |r| r.macro == :belongs_to }.
10-
index_by{ |r| r.foreign_key.to_sym }
9+
select { |r| r.macro == :belongs_to }.
10+
index_by { |r| r.foreign_key.to_sym }
1111
end
1212

1313
def primary_col?(c)
@@ -20,4 +20,3 @@ def sti_col?(c)
2020
end
2121
end
2222
end
23-

lib/meta_search/searches/mongoid.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class MongoidSearchBuilder < SimpleDelegator
1010
def initialize relation, params, options
1111
super(relation)
1212
@relation = relation
13-
@params, @options = params, options
13+
@params = params
14+
@options = options
1415
end
1516

1617
def build
@@ -78,7 +79,6 @@ def method_missing name, *attrs, &block
7879
relation.send(name, *attrs, &block)
7980
end
8081

81-
8282
def respond_to? name, include_private = false
8383
name.to_s =~ metasearch_regexp or super
8484
end
@@ -92,8 +92,8 @@ def method_missing name, *args, &block
9292
end
9393

9494
def metasearch_regexp
95-
field_names = klass.fields.map{ |field| field.second.name }
96-
conditions = MetaSearch::DEFAULT_WHERES.map {|condition| condition[0...-1]} # pop tail options
95+
field_names = klass.fields.map { |field| field.second.name }
96+
conditions = MetaSearch::DEFAULT_WHERES.map { |condition| condition[0...-1] } # pop tail options
9797

9898
/\A(#{field_names.join('|')})_(#{conditions.join('|')})\z/
9999
end

spec/features/smoke_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
require 'spec_helper'
32

43
describe 'browse the test app' do
@@ -66,7 +65,6 @@
6665
end
6766

6867
context 'with 1 post' do
69-
7068
before do
7169
Post.create!(title: 'Quick Brown Fox', body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user)
7270

@@ -232,7 +230,7 @@
232230
Post.where(body: 'The quick brown fox jumps over the lazy dog.').update_all(author: { name: 'Bob', city: { name: 'Washington' } })
233231
post.author = Author.new name: 'Adam', city: { name: 'California' }
234232
post.save!
235-
Post.all.each{|p| p.author.city }
233+
Post.all.each { |p| p.author.city }
236234
end
237235

238236
it 'sorts by the embedded document field' do
@@ -275,7 +273,7 @@
275273
display_total_text = I18n.t 'active_admin.pagination.multiple',
276274
model: 'Posts', total: posts_size,
277275
from: offset + 1, to: offset + collection_size
278-
display_total_text = Nokogiri::HTML(display_total_text).text.gsub(' ', ' ')
276+
display_total_text = Nokogiri::HTML(display_total_text).text.gsub(' ', ' ')
279277
pagination_information = page.find('.pagination_information').text
280278
expect(pagination_information).to include(display_total_text)
281279
end
@@ -316,8 +314,6 @@
316314
visit '/admin/admin_users.csv'
317315
expect(page.status_code).to eq(200) or eq(304)
318316
end
319-
320-
321317
end
322318
end
323319
end

spec/lib/active_admin/mongoid/filter_form_builder_spec.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@
6060
it { is_expected.to eq :string }
6161
end
6262

63-
64-
# when :date, :datetime, :time; :date_range
65-
# when :string, :text, :object; :string
66-
# when :float, :decimal; :numeric
67-
# when :integer
68-
63+
# when :date, :datetime, :time; :date_range
64+
# when :string, :text, :object; :string
65+
# when :float, :decimal; :numeric
66+
# when :integer
6967
end
7068
end

spec/spec_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
end
1212
end
1313

14-
require File.expand_path("../../test_app/config/environment", __FILE__)
14+
require File.expand_path('../test_app/config/environment', __dir__)
1515
require 'rspec/rails'
1616

1717
# Requires supporting ruby files with custom matchers and macros, etc,
1818
# in spec/support/ and its subdirectories.
19-
Dir[File.join(File.expand_path("../../", __FILE__), "spec/support/**/*.rb")].each {|f| require f}
20-
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
19+
Dir[File.join(File.expand_path('..', __dir__), "spec/support/**/*.rb")].each { |f| require f }
20+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
2121

2222
RSpec.configure do |config|
2323
# ## Mock Framework

spec/support/debug.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
def debugit( *args, &block )
2-
it( *args, { driver: :poltergeist_debug, inspector: true }, &block )
1+
def debugit(*args, &block)
2+
it(*args, { driver: :poltergeist_debug, inspector: true }, &block)
33
end

spec/support/mongoid.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'pathname'
22
require 'mongoid'
3-
root = Pathname(File.expand_path('../../../test_app', __FILE__))
3+
root = Pathname(File.expand_path('../../test_app', __dir__))
44
version = Mongoid::VERSION.to_i
55

66
current_config = root.join("config/mongoid.#{version}.yml").read
77
config_file = root.join('config/mongoid.yml')
8-
config_file.open('w') {|c| c << current_config }
8+
config_file.open('w') { |c| c << current_config }
99

1010
Mongoid.load!(config_file, :test)
1111
Mongo::Logger.logger.level = ::Logger::FATAL

tasks/js.rake

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
namespace :js do
2-
32
desc "Compile the JS for Rails apps without Asset Pipeline"
43
task :compile do
54
require 'sprockets'
@@ -28,5 +27,4 @@ namespace :js do
2827

2928
FileUtils.mv tmp_base_js, base_js
3029
end
31-
3230
end

tasks/test.rake

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ end
77

88
# Run specs and cukes
99
desc "Run the full suite"
10-
task :test => ['spec:unit', 'spec:integration']
10+
task test: ['spec:unit', 'spec:integration']
1111

1212
namespace :test do
13-
1413
def run_tests_against(*versions)
1514
current_version = detect_rails_version if File.exists?("Gemfile.lock")
1615

@@ -33,16 +32,14 @@ namespace :test do
3332
end
3433

3534
desc "Alias for major_supported_rails"
36-
task :all => :major_supported_rails
37-
35+
task all: :major_supported_rails
3836
end
3937

4038
require 'rspec/core/rake_task'
4139

4240
RSpec::Core::RakeTask.new(:spec)
4341

4442
namespace :spec do
45-
4643
desc "Run the unit specs"
4744
RSpec::Core::RakeTask.new(:unit) do |t|
4845
t.pattern = "spec/unit/**/*_spec.rb"
@@ -52,7 +49,6 @@ namespace :spec do
5249
RSpec::Core::RakeTask.new(:integration) do |t|
5350
t.pattern = "spec/integration/**/*_spec.rb"
5451
end
55-
5652
end
5753

5854
#

test_app/Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Add your own tasks in files placed in lib/tasks ending in .rake,
33
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
44

5-
require File.expand_path('../config/application', __FILE__)
5+
require File.expand_path('config/application', __dir__)
66

77
TestApp::Application.load_tasks

test_app/app/admin/dashboard.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
ActiveAdmin.register_page "Dashboard" do
2+
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
23

3-
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
4-
5-
content :title => proc{ I18n.t("active_admin.dashboard") } do
6-
div :class => "blank_slate_container", :id => "dashboard_default_message" do
7-
span :class => "blank_slate" do
4+
content title: proc { I18n.t("active_admin.dashboard") } do
5+
div class: "blank_slate_container", id: "dashboard_default_message" do
6+
span class: "blank_slate" do
87
span I18n.t("active_admin.dashboard_welcome.welcome")
98
small I18n.t("active_admin.dashboard_welcome.call_to_action")
109
end

test_app/app/admin/posts.rb

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
filter :admin_user, as: :select
1111
filter :other_user, as: :check_boxes
1212

13-
1413
index do
1514
selectable_column
1615
column :title

test_app/app/models/admin_user.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ class AdminUser
77
:recoverable, :rememberable, :trackable, :validatable
88

99
## Database authenticatable
10-
field :email, :type => String, :default => ""
11-
field :encrypted_password, :type => String, :default => ""
10+
field :email, type: String, default: ""
11+
field :encrypted_password, type: String, default: ""
1212

1313
## Recoverable
14-
field :reset_password_token, :type => String
15-
field :reset_password_sent_at, :type => Time
14+
field :reset_password_token, type: String
15+
field :reset_password_sent_at, type: Time
1616

1717
## Rememberable
18-
field :remember_created_at, :type => Time
18+
field :remember_created_at, type: Time
1919

2020
## Trackable
21-
field :sign_in_count, :type => Integer, :default => 0
22-
field :current_sign_in_at, :type => Time
23-
field :last_sign_in_at, :type => Time
24-
field :current_sign_in_ip, :type => String
25-
field :last_sign_in_ip, :type => String
21+
field :sign_in_count, type: Integer, default: 0
22+
field :current_sign_in_at, type: Time
23+
field :last_sign_in_at, type: Time
24+
field :current_sign_in_ip, type: String
25+
field :last_sign_in_ip, type: String
2626

2727
has_many :posts
28-
28+
2929
def name
3030
email
3131
end

0 commit comments

Comments
 (0)