- Ruby version: 3.4.5
- Rails version: 8.0.3
- Ruby on Rails
- RSpec for testing
- Turbo for interactivity
- Cucumber for BDD (though not fully implemented due to Capybara issues)
- Net::HTTP for API requests
- Simple caching with Rails.cache
- Tailwind.css for styling
- brakeman for security checks
- rubocop for linting
- simplecov for test coverage
- Fasterer for performance improvements
- Weather API (weatherapi.com) for weather data
- dotenv-rails for environment variable management
- Github Actions for CI/CD
- Need to set the following env vars:
WEATHER_API_KEY: API key for weatherapi.comWEATHER_API_URL: Base URL for the weather API (default: http://api.weatherapi.com/v1)
- Weather API : Used to fetch weather data.
the object it uses is too big to paste it its entirety, and we're only using a few fields from it. It takes either a city or zipcode as a param, so we accept either or both, and prefer zipcode when both are used. It returns current weather conditions, as well as a 5-day forecast.
- In-memory caching is implemented using Rails.cache, with a TTL of 30 minutes, for calls made with zip-codes. This is to reduce the number of API calls and improve performance. Cached data is used if available, otherwise a new API call is made.
- Includes Routing, Request and Service unit tests
- Testing instructions
bundle exec rspec -f doc - NOTE: I had plans for cucumber tests, they looked promising, except Capybara's webdriver doesn't really play nice with JS, so does not register changes made by JS, including through turbo... so scrapped them for now. The feature scenarios and step definitions themselves are included for reference.
Feature: User gets weather forecast
A user visits the site and looks up weather forecast data for their address
Scenario: User provides valid city
Given I visit the weather forecast page
When I enter 'Denver, CO' into the 'city' field
And I click the 'Get Forecast' button
Then I should see the current weather conditions
And I should see a 5-day weather forecast
And I should see appropriate weather icons for each day
Scenario: User provides invalid city name
Given I visit the weather forecast page
When I enter 'InvalidCity' into the 'city' field
And I click the 'Get Forecast' button
Then I should not see any weather data
Scenario: User provides valid zip code
Given I visit the weather forecast page
When I enter '80202' into the 'zip' field
And I click the 'Get Forecast' button
Then I should see the current weather conditions
And I should see a 5-day weather forecast
And I should see appropriate weather icons for each day
Scenario: User provides zip code for cached value
Given I visit the weather forecast page
And the value for zip code '80202' is cached
When I enter '80202' into the 'zip' field
And I click the 'Get Forecast' button
Then I should see the current weather conditions
And I should see a 5-day weather forecast
And I should see appropriate weather icons for each day
And I should see an indicator that the data was retrieved from cache
Scenario: User provides invalid zip code
Given I visit the weather forecast page
When I enter '99999' into the 'zip' field
And I click the 'Get Forecast' button
Then I should not see any weather data- Uses YARD to generate documentation from code comments
- To generate docs, run:
yard doc - To view docs, open
doc/index.htmlin a web browser - can also be viewed by running
yard serverand visitinghttp://localhost:8808in a web browser