diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 0000000..6fb951d --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,15 @@ +name: Rubocop + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - run: bundle exec rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..61ffe3d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Test + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + services: + mongo: + image: mongo:7 + ports: ["27017:27017"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + + - name: Run tests + run: bundle exec rspec diff --git a/.rubocop.yml b/.rubocop.yml index 4eeca58..867ae8a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,11 @@ +inherit_from: .rubocop_todo.yml + AllCops: NewCops: enable TargetRubyVersion: 3.1 + +plugins: + - rubocop-rake # Overwrite or add rules to create your own house style # # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..fae6a50 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,58 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2026-02-04 21:23:09 UTC using RuboCop version 1.84.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Gemspec/DuplicatedAssignment: + Exclude: + - 'mongoid-geospatial.gemspec' + +# Offense count: 4 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 26 + +# Offense count: 25 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 259 + +# Offense count: 4 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 25 + +# Offense count: 3 +Style/ClassVars: + Exclude: + - 'lib/mongoid/geospatial.rb' + +# Offense count: 3 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/mongoid/geospatial/config.rb' + - 'lib/mongoid/geospatial/config/point.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self, forbidden +Style/ModuleFunction: + Exclude: + - 'lib/mongoid/geospatial/config.rb' + - 'lib/mongoid/geospatial/config/point.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings. +# URISchemes: http, https +Layout/LineLength: + Max: 135 diff --git a/Gemfile b/Gemfile index 545f378..e72f6ec 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,8 @@ group :development, :test do gem 'reline' gem 'rgeo' gem 'rubocop' + gem 'rubocop-rake' + gem 'yard' end group :test do diff --git a/README.md b/README.md index cc1914e..99126d6 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,8 @@ A Mongoid Extension that simplifies the use of MongoDB spatial features. [![Gem Version](https://badge.fury.io/rb/mongoid-geospatial.svg)](http://badge.fury.io/rb/mongoid-geospatial) +[![Test](https://github.com/mongoid/mongoid-geospatial/actions/workflows/test.yml/badge.svg)](https://github.com/mongoid/mongoid-geospatial/actions/workflows/test.yml) [![Code Climate](https://codeclimate.com/github/mongoid/mongoid-geospatial.svg)](https://codeclimate.com/github/mongoid/mongoid-geospatial) -[![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-geospatial/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-geospatial?branch=master) -[![Build Status](https://travis-ci.org/mongoid/mongoid-geospatial.svg?branch=master)](https://travis-ci.org/mongoid/mongoid-geospatial) ## Quick Start diff --git a/spec/benchmark/geolibs b/spec/benchmark/geolibs index aaedb06..e2bf5e3 100755 --- a/spec/benchmark/geolibs +++ b/spec/benchmark/geolibs @@ -15,18 +15,21 @@ Mongoid.load!(File.expand_path('mongoid.yml', __dir__), :test) class NoGeo include Mongoid::Document + field :name end class Rider include Mongoid::Document include Mongoid::Geospatial + field :name end class Cafe include Mongoid::Document include Mongoid::Geospatial + field :name field :spot, type: Point end diff --git a/spec/benchmark/geonear b/spec/benchmark/geonear old mode 100644 new mode 100755 index 373d5ea..a9895e9 --- a/spec/benchmark/geonear +++ b/spec/benchmark/geonear @@ -11,6 +11,7 @@ Mongoid.load!(File.expand_path('../mongoid.yml', __dir__), :test) class Cafe include Mongoid::Document include Mongoid::Geospatial + field :name field :geom, type: Point, spatial: true spatial_index :geom @@ -20,6 +21,7 @@ end class Cafe2d include Mongoid::Document include Mongoid::Geospatial + field :name field :geom, type: Point, sphere: true spherical_index :geom diff --git a/spec/models/phone.rb b/spec/models/phone.rb index d5e0e25..b8bf7e7 100644 --- a/spec/models/phone.rb +++ b/spec/models/phone.rb @@ -3,6 +3,7 @@ # Sample spec class class Phone include Mongoid::Document + field :number embeds_one :country_code