Skip to content

Commit

Permalink
Final mixed misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jlurena committed Jul 11, 2024
1 parent 5fcc5b3 commit d6e4000
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pkg/*
.ruby-version
.tool-versions
coverage
.standard_todo.yml
60 changes: 60 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM bash AS base

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV ASDF_DIR=/root/.asdf \
GEM_HOME=/root/gems \
PATH=/root/gems/bin:$PATH

# Install dependencies
RUN apk update && \
apk add --no-cache \
build-base \
git \
libffi-dev \
openssl-dev \
readline-dev \
tzdata \
yaml-dev \
zlib-dev

RUN git clone https://github.com/asdf-vm/asdf.git /root/.asdf --branch v0.14.0 && \
. "$ASDF_DIR/asdf.sh" && \
asdf plugin add ruby

## For parallelism, build in stages
# Ruby 3.1.4
FROM base AS ruby-3.1.4
RUN . "$ASDF_DIR/asdf.sh" && \
asdf install ruby 3.1.4 && \
asdf global ruby 3.1.4 && \
gem install bundler

# Ruby 3.2.2
FROM base AS ruby-3.2.2
RUN . "$ASDF_DIR/asdf.sh" && \
asdf install ruby 3.2.2 && \
asdf global ruby 3.2.2 && \
gem install bundler

# Final Image with Application Code
FROM base AS final

ENV GEM_HOME=/root/gems \
PATH=/root/gems/bin:$PATH

# Copy and merge installed ASDF directory from ruby versions
COPY --from=ruby-3.1.4 /root/.asdf /tmp/.asdf-3.1.4
COPY --from=ruby-3.2.2 /root/.asdf /tmp/.asdf-3.2.2
RUN cp -rn /tmp/.asdf-3.1.4/* /root/.asdf && rm -rf /tmp/.asdf-3.1.4
RUN cp -rn /tmp/.asdf-3.2.2/* /root/.asdf && rm -rf /tmp/.asdf-3.2.2

WORKDIR /app

COPY gemfiles gemfiles
COPY lib lib
COPY spec spec
COPY cached_resource.gemspec Gemfile Rakefile scripts/docker/run_tests.sh .

# Run tests or any other final commands
CMD ["./run_tests.sh"]
48 changes: 15 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,27 @@ Since resources are cached with an argument based key, you may pass in extra dat
MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
```

## Testing
## Contribution
### Testing
#### Locally
You can set `TEST_RAILS_VERSION` to a value of the supported Rails versions in the [Compatability Matrix](#compatibility), or bundler will automatically select a version.

To test the Ruby + Rails combination configured by default:
Examples:
- `TEST_RAILS_VERSION=7.1 bundle exec rspec # runs test suite + linter`
- `bundle exec rspec # Runs test suite`

```bash
$ rake
#### With Docker
```sh
docker build -t cached_resource_test -f Dockerfile.test .
docker run --rm -v ${PWD}/coverage:/app/coverage cached_resource_test
```

or to test all supported environments...you have to do a little more work...
### Code Coverage
Coverage can be found found within `coverage/index.html` after every test run.

Switch your Ruby version to the desired version. This project's maintainer uses `asdf`, so switching to Ruby 3 looks like this:
### Linter
We unconfigurable linting rules from [Standard](https://github.com/standardrb/standard)

```bash
$ asdf local ruby 3.0.5
```

If you have a `Gemfile.lock`, delete it:

```bash
$ rm Gemfile.lock
```

Then reinstall your dependencies:

```bash
$ bundle install
```

and finally, run the tests:

```bash
$ rake
```

If you want to test with a specific Rails version, start over and install dependencies with `TEST_RAILS_VERSION` set:

```bash
$ TEST_RAILS_VERSION=6.1 bundle install
```

## Credit/Inspiration
* quamen and [this gist](http://gist.github.com/947734)
Expand Down
2 changes: 1 addition & 1 deletion lib/cached_resource/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def name_key
else
"#{cached_resource.cache_key_prefix}/"
end
prefix + name.parameterize.tr("-", "/")
prefix.to_s + name.parameterize.tr("-", "/")
end
end

Expand Down
28 changes: 28 additions & 0 deletions scripts/docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -e

# Matrix of Ruby and Rails versions
RUBY_VERSIONS="3.1.4 3.2.2"
RAILS_VERSIONS="6.1 7.0 7.1"

# Iterate over Ruby versions
for RUBY_VERSION in $RUBY_VERSIONS; do
. "$ASDF_DIR/asdf.sh"
asdf local ruby $RUBY_VERSION

# Iterate over Rails versions
for RAILS_VERSION in $RAILS_VERSIONS; do
# Set the Rails version environment variable
export TEST_RAILS_VERSION=$RAILS_VERSION
echo "Testing with Ruby $RUBY_VERSION and Rails $RAILS_VERSION"

# Install gems
bundle install

# Run tests
bundle exec rspec
done
done

bundle exec standardrb --generate-todo
2 changes: 1 addition & 1 deletion spec/cached_resource/cached_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
end

it "requires concurrent/promise" do
expect { dummy_class.setup_cached_resource!(concurrent_write: true) }.not_to raise_error(LoadError)
expect { dummy_class.setup_cached_resource!(concurrent_write: true) }.not_to raise_error
end

context 'When "concurrent/promise" is not installed' do
Expand Down

0 comments on commit d6e4000

Please sign in to comment.