diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml new file mode 100644 index 0000000..8a8975b --- /dev/null +++ b/.github/workflows/rubyonrails.yml @@ -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 diff --git a/Gemfile b/Gemfile index 2460e3e..d67769b 100644 --- a/Gemfile +++ b/Gemfile @@ -75,4 +75,4 @@ gem "devise", "~> 4.9" gem "bootstrap", "~> 5.3" -gem 'sassc-rails' \ No newline at end of file +gem 'sassc-rails' diff --git a/spec/helpers/comment_helper_spec.rb b/spec/helpers/comment_helper_spec.rb deleted file mode 100644 index fbb3c9c..0000000 --- a/spec/helpers/comment_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the CommentHelper. For example: -# -# describe CommentHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe CommentHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/reactions_helper_spec.rb b/spec/helpers/reactions_helper_spec.rb deleted file mode 100644 index 8101969..0000000 --- a/spec/helpers/reactions_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the ReactionsHelper. For example: -# -# describe ReactionsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe ReactionsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/comments/edit.html.erb_spec.rb b/spec/views/comments/edit.html.erb_spec.rb index 57ae5b3..65f8f02 100644 --- a/spec/views/comments/edit.html.erb_spec.rb +++ b/spec/views/comments/edit.html.erb_spec.rb @@ -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 diff --git a/spec/views/comments/index.html.erb_spec.rb b/spec/views/comments/index.html.erb_spec.rb index 9d2dd6c..4260fe6 100644 --- a/spec/views/comments/index.html.erb_spec.rb +++ b/spec/views/comments/index.html.erb_spec.rb @@ -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 diff --git a/spec/views/comments/new.html.erb_spec.rb b/spec/views/comments/new.html.erb_spec.rb index 0249701..474041b 100644 --- a/spec/views/comments/new.html.erb_spec.rb +++ b/spec/views/comments/new.html.erb_spec.rb @@ -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 diff --git a/spec/views/comments/show.html.erb_spec.rb b/spec/views/comments/show.html.erb_spec.rb index bb6bf8d..e7f3c4e 100644 --- a/spec/views/comments/show.html.erb_spec.rb +++ b/spec/views/comments/show.html.erb_spec.rb @@ -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