Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github action to run rspec on PRs #63

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.
#
# This workflow will install a prebuilt Ruby version, install dependencies, and
# run tests and linters.
name: "Ruby on Rails CI"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
env:
DB_CONNECTION: sqlite3
DB_DATABASE: test.sqlite3
steps:
- name: Create Database
run: touch test.sqlite3
- name: Checkout code
uses: actions/checkout@v4
# Add or replace dependency steps here
- name: Install Ruby and gems
uses: ruby/setup-ruby@78c01b705fd9d5ad960d432d3a0cfa341d50e410 # v1.179.1
with:
bundler-cache: true
# Add or replace database setup steps here
- name: Set up database schema
run: bin/rails db:schema:load
# Add or replace test runners here
- name: Run tests
run: bin/rake
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ gem "devise", "~> 4.9"

gem "bootstrap", "~> 5.3"

gem 'sassc-rails'
gem 'sassc-rails'
15 changes: 0 additions & 15 deletions spec/helpers/comment_helper_spec.rb

This file was deleted.

15 changes: 0 additions & 15 deletions spec/helpers/reactions_helper_spec.rb

This file was deleted.

66 changes: 34 additions & 32 deletions spec/views/comments/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
require 'rails_helper'

RSpec.describe "comments/edit.html.erb", type: :view do
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }

before do
assign(:entry, entry)
assign(:comment, comment)
render
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }

context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the heading" do
expect(rendered).to have_selector("h1", text: "Edit comment")
end

it "renders the form to edit comment" do
expect(rendered).to have_selector("form[action='#{entry_comment_path(entry, comment)}'][method='post']")
end

it "pre-fills the text area with the current comment" do
expect(rendered).to have_selector("textarea[name='comment[text]']", text: comment.text)
end

it "displays the submit button" do
expect(rendered).to have_selector("input[type='submit'][value='Update']")
end

it "has a link to show the comment" do
expect(rendered).to have_link('Show this comment', href: entry_comments_path(entry, comment))
end

it "has a link to go back to the comments index" do
expect(rendered).to have_link('Back to comment', href: entry_comments_path(entry))
end
end

it "displays the heading" do
expect(rendered).to have_selector("h1", text: "Edit comment")
end

it "renders the form to edit comment" do
expect(rendered).to have_selector("form[action='#{entry_comment_path(entry, comment)}'][method='post']")
end

it "pre-fills the text area with the current comment" do
expect(rendered).to have_selector("textarea[name='comment[text]']", text: comment.text)
end

it "displays the submit button" do
expect(rendered).to have_selector("input[type='submit'][value='Update']")
end

it "has a link to show the comment" do
expect(rendered).to have_link('Show this comment', href: entry_comments_path(entry, comment))
end

it "has a link to go back to the comments index" do
expect(rendered).to have_link('Back to comment', href: entry_comments_path(entry))
end
end
39 changes: 20 additions & 19 deletions spec/views/comments/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
require 'rails_helper'

RSpec.describe "comments/index.html.erb", type: :view do
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comments) { FactoryBot.create_list(:comment, 2, entry: entry, user: user) }
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comments) { FactoryBot.create_list(:comment, 2, entry: entry, user: user) }

before do
assign(:entry, entry)
assign(:comments, comments)
render
end
context "web page text" do
before do
assign(:entry, entry)
assign(:comments, comments)
render
end

it "displays the entry" do
expect(rendered).to include(entry.text)
end
it "displays the entry" do
expect(rendered).to include(entry.text)
end

it "displays all comments for that entry" do
comments.each do |comment|
expect(rendered).to include(comment.user.email)
expect(rendered).to include(comment.text)
it "displays all comments for that entry" do
comments.each do |comment|
expect(rendered).to include(comment.user.email)
expect(rendered).to include(comment.text)
end
end
end

it "displays a link back to the entry" do
expect(rendered).to have_link("Back to entry", href: entry_path(entry))
it "displays a link back to the entry" do
expect(rendered).to have_link("Back to entry", href: entry_path(entry))
end
end

end
30 changes: 16 additions & 14 deletions spec/views/comments/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
require 'rails_helper'

RSpec.describe "comments/new.html.erb", type: :view do
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let(:comment) { FactoryBot.create(:comment, entry: entry) }
let(:user) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comment) { FactoryBot.create(:comment, entry: entry) }

before do
assign(:entry, entry)
assign(:comment, comment)
render
end
context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the new comment form" do
expect(rendered).to have_selector("h1", text: "New comment")
expect(rendered).to render_template(partial: "_form")
end
it "displays the new comment form" do
expect(rendered).to have_selector("h1", text: "New comment")
expect(rendered).to render_template(partial: "_form")
end

it "renders a link back to comments index" do
expect(rendered).to have_link("Back to comments", href: comments_index_path)
it "renders a link back to comments index" do
expect(rendered).to have_link("Back to comments", href: comments_index_path)
end
end
end
61 changes: 31 additions & 30 deletions spec/views/comments/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
require 'rails_helper'

RSpec.describe "comments/show.html.erb", type: :view do
let(:user) { FactoryBot.create(:user) }
let(:friend) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: friend) }
let(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }


before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the comment" do
expect(rendered).to include("Test comment")
end

it "renders the partial for the comment" do
expect(rendered).to include(comment.text)
end

it "displays the edit link" do
expect(rendered).to have_link("Edit", href: edit_entry_comment_path(entry, comment))
end

it "displays the back to entry link" do
expect(rendered).to have_link("My Entries", href: entries_path)
end

it "displays my friends entries" do
expect(rendered).to have_link("Friends Entries", href: friend_entries_path)
let(:user) { FactoryBot.create(:user) }
let!(:friend) { FactoryBot.create(:user) }
let(:entry) { FactoryBot.create(:entry, user: friend) }
let!(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }

context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the comment" do
expect(rendered).to include("Test comment")
end

it "renders the partial for the comment" do
expect(rendered).to include(comment.text)
end

it "displays the edit link" do
expect(rendered).to have_link("Edit", href: edit_entry_comment_path(entry, comment))
end

it "displays the back to entry link" do
expect(rendered).to have_link("My Entries", href: entries_path)
end

it "displays my friends entries" do
expect(rendered).to have_link("Friends Entries", href: friend_entries_path)
end
end
end
Loading