diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1d3af85 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: CI + +on: + push: + branches: [master, main] + pull_request: + +jobs: + rspec: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + + - run: bundle exec rspec diff --git a/.github/workflows/claude_review.yaml b/.github/workflows/claude_review.yaml new file mode 100644 index 0000000..e1eeadf --- /dev/null +++ b/.github/workflows/claude_review.yaml @@ -0,0 +1,21 @@ +name: Claude Code + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + +permissions: + contents: read + pull-requests: write + issues: read + id-token: write + actions: read + +jobs: + claude: + uses: budacom/github-actions/.github/workflows/reusable_claude_review.yaml@workflows-v8 + with: + model: claude-haiku-4-5 + secrets: inherit diff --git a/.gitignore b/.gitignore index 76eb7d9..46d189f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -Gemfile.lock .rubocop-https---raw-githubusercontent-com-budacom-rubocop-config-main-rubocop-base-yml diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..2f4b607 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.4 diff --git a/Gemfile b/Gemfile index 71139e2..aa433fa 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,7 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in internal-affairs-gem.gemspec -gemspec \ No newline at end of file +gemspec + +# Minimum stack to boot specs (Stage 1) +gem 'rails' +gem 'active_admin_resource', github: 'budacom/activeadmin_resource' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a4f069e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,339 @@ +GIT + remote: https://github.com/budacom/activeadmin_resource.git + revision: 02e4badba35827580f802b1afc816679c153f6cc + specs: + active_admin_resource (0.1.4) + activeadmin + activeresource + authograph + enumerize (~> 2.2) + formtastic + monetize (~> 1.9.0) + money (~> 6.6) + money-rails (~> 1.5) + +PATH + remote: . + specs: + buda_active_resource (1.0.0) + activeadmin + activeresource + authograph + enumerize + +GEM + remote: https://rubygems.org/ + specs: + action_text-trix (2.1.19) + railties + actioncable (8.1.3) + actionpack (= 8.1.3) + activesupport (= 8.1.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.1.3) + actionpack (= 8.1.3) + activejob (= 8.1.3) + activerecord (= 8.1.3) + activestorage (= 8.1.3) + activesupport (= 8.1.3) + mail (>= 2.8.0) + actionmailer (8.1.3) + actionpack (= 8.1.3) + actionview (= 8.1.3) + activejob (= 8.1.3) + activesupport (= 8.1.3) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.1.3) + actionview (= 8.1.3) + activesupport (= 8.1.3) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.1.3) + action_text-trix (~> 2.1.15) + actionpack (= 8.1.3) + activerecord (= 8.1.3) + activestorage (= 8.1.3) + activesupport (= 8.1.3) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.1.3) + activesupport (= 8.1.3) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activeadmin (3.5.1) + arbre (~> 1.2, >= 1.2.1) + csv + formtastic (>= 3.1) + formtastic_i18n (>= 0.4) + inherited_resources (~> 1.7) + jquery-rails (>= 4.2) + kaminari (>= 1.2.1) + railties (>= 6.1) + ransack (>= 4.0) + activejob (8.1.3) + activesupport (= 8.1.3) + globalid (>= 0.3.6) + activemodel (8.1.3) + activesupport (= 8.1.3) + activemodel-serializers-xml (1.0.3) + activemodel (>= 5.0.0.a) + activesupport (>= 5.0.0.a) + builder (~> 3.1) + activerecord (8.1.3) + activemodel (= 8.1.3) + activesupport (= 8.1.3) + timeout (>= 0.4.0) + activeresource (6.2.0) + activemodel (>= 7.0) + activemodel-serializers-xml (~> 1.0) + activesupport (>= 7.0) + activestorage (8.1.3) + actionpack (= 8.1.3) + activejob (= 8.1.3) + activerecord (= 8.1.3) + activesupport (= 8.1.3) + marcel (~> 1.0) + activesupport (8.1.3) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + json + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + arbre (1.7.0) + activesupport (>= 3.0.0) + ruby2_keywords (>= 0.0.2) + authograph (1.0.5) + base64 (0.3.0) + bigdecimal (4.1.2) + builder (3.3.0) + coderay (1.1.3) + concurrent-ruby (1.3.7) + connection_pool (3.0.2) + crass (1.0.7) + csv (3.3.5) + date (3.5.1) + diff-lcs (1.6.2) + drb (2.2.3) + enumerize (2.8.1) + activesupport (>= 3.2) + erb (6.0.4) + erubi (1.13.1) + formtastic (6.0.0) + actionpack (>= 7.2.0) + formtastic_i18n (0.7.0) + globalid (1.4.0) + activesupport (>= 6.1) + has_scope (0.9.0) + actionpack (>= 7.0) + activesupport (>= 7.0) + i18n (1.15.2) + concurrent-ruby (~> 1.0) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) + io-console (0.8.2) + irb (1.18.0) + pp (>= 0.6.0) + prism (>= 1.3.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jquery-rails (4.6.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.20.0) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) + logger (1.7.0) + loofah (2.25.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.9.1) + logger + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.2.1) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (6.0.6) + drb (~> 2.0) + prism (~> 1.5) + monetize (1.9.4) + money (~> 6.12) + money (6.19.0) + i18n (>= 0.6.4, <= 2) + money-rails (1.15.0) + activesupport (>= 3.0) + monetize (~> 1.9) + money (~> 6.13) + railties (>= 3.0) + net-imap (0.6.4.1) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.4-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.4-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.19.4-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.4-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.19.4-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.4-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.4-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.4-x86_64-linux-musl) + racc (~> 1.4) + pp (0.6.4) + prettyprint + prettyprint (0.2.0) + prism (1.9.0) + pry (0.16.0) + coderay (~> 1.1) + method_source (~> 1.0) + reline (>= 0.6.0) + racc (1.8.1) + rack (3.2.6) + rack-session (2.1.2) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.3.1) + rack (>= 3) + rails (8.1.3) + actioncable (= 8.1.3) + actionmailbox (= 8.1.3) + actionmailer (= 8.1.3) + actionpack (= 8.1.3) + actiontext (= 8.1.3) + actionview (= 8.1.3) + activejob (= 8.1.3) + activemodel (= 8.1.3) + activerecord (= 8.1.3) + activestorage (= 8.1.3) + activesupport (= 8.1.3) + bundler (>= 1.15.0) + railties (= 8.1.3) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.7.0) + loofah (~> 2.25) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.1.3) + actionpack (= 8.1.3) + activesupport (= 8.1.3) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.4.2) + ransack (4.4.1) + activerecord (>= 7.2) + activesupport (>= 7.2) + i18n + rbs (4.0.3) + logger + prism (>= 1.6.0) + tsort + rdoc (8.0.0) + erb + prism (>= 1.6.0) + rbs (>= 4.0.0) + tsort + reline (0.6.3) + io-console (~> 0.5) + responders (3.2.0) + actionpack (>= 7.0) + railties (>= 7.0) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + ruby2_keywords (0.0.5) + securerandom (0.4.1) + thor (1.5.0) + timeout (0.6.1) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.1.1) + useragent (0.16.11) + websocket-driver (0.8.2) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.8.2) + +PLATFORMS + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + active_admin_resource! + buda_active_resource! + pry + rails + rspec + +BUNDLED WITH + 2.6.9 diff --git a/README.md b/README.md index ff18049..adabc35 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,18 @@ Features include: - Integration with `Money` - Connectiones patch - other minor tweaks + +## Running specs + +Requires Ruby 3.4 (see `.ruby-version`). + +```bash +bundle install +bundle exec rspec +``` + +Or: + +```bash +bin/ci +``` diff --git a/bin/ci b/bin/ci new file mode 100755 index 0000000..cb9d618 --- /dev/null +++ b/bin/ci @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$0")/.." + +bundle check || bundle install +bundle exec rspec "$@" diff --git a/spec/lib/resource_api_mock_spec.rb b/spec/lib/resource_api_mock_spec.rb index 51cdca4..6b82a18 100644 --- a/spec/lib/resource_api_mock_spec.rb +++ b/spec/lib/resource_api_mock_spec.rb @@ -4,6 +4,7 @@ describe ActiveAdminResource::ResourceApiMock do class Zoo attr_accessor :id + def initialize(id) self.id = id end @@ -22,6 +23,10 @@ class Giraffe < ActiveAdminResource::Base end end + def record_ids(records) + records.map(&:id) + end + let(:super_zoo) { Zoo.new(1) } let!(:tall_jimmy) do Giraffe.create(name: 'Jimmy', zoo_id: super_zoo.id, height: 4.9, color: 'brown') @@ -32,27 +37,28 @@ class Giraffe < ActiveAdminResource::Base describe 'unfiltered query via #all' do it 'finds the created records' do - expect(Giraffe.all).to eq([tall_jimmy, small_george]) + expect(record_ids(Giraffe.all)).to eq([tall_jimmy.id, small_george.id]) end end describe 'filtered query via #where' do it 'gets the corresponding records' do - expect(Giraffe.where(color: 'brown')).to eq([tall_jimmy]) - expect(Giraffe.where(zoo: super_zoo)).to eq([tall_jimmy, small_george]) + expect(record_ids(Giraffe.where(color: 'brown'))).to eq([tall_jimmy.id]) + expect(record_ids(Giraffe.where(zoo: super_zoo))).to eq([tall_jimmy.id, small_george.id]) end end describe 'get single record via #find()' do it 'gets the corresponding record' do - expect(Giraffe.find(57)).to eq(small_george) + expect(Giraffe.find(57).id).to eq(small_george.id) end end describe '#destroy' do before { tall_jimmy.destroy } + it "doesn't find the record anymore" do - expect(Giraffe.all).to eq([small_george]) + expect(record_ids(Giraffe.all)).to eq([small_george.id]) end end @@ -61,9 +67,13 @@ class Giraffe < ActiveAdminResource::Base small_george.color = 'black' small_george.save end + it 'updates record on store' do expect(small_george.reload.color).to eq('black') - expect(Giraffe.where(color: 'black')).to eq([small_george]) + results = Giraffe.where(color: 'black') + expect(results.size).to eq(1) + expect(results.first.id).to eq(small_george.id) + expect(results.first.color).to eq('black') end end end