From 980864cad62a7505b218c52df0b8c3bcf6452379 Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Mon, 10 Aug 2020 23:08:58 -0400 Subject: [PATCH] WIP: added post specs from DRAW --- .../better_together/posts_controller_spec.rb | 144 ++++++++++++++++++ .../better_together/posts_controller_spec.rb | 62 ++++++++ .../better_together_posts_spec.rb | 10 ++ .../better_together/posts_routing_spec.rb.tmp | 38 +++++ .../better_together/posts_routing_spec.rb.tmp | 39 +++++ .../posts/edit.html.slim_spec.rb | 18 +++ .../posts/index.html.slim_spec.rb | 12 ++ .../posts/new.html.slim_spec.rb | 18 +++ .../posts/index.html.slim_spec.rb | 21 +++ .../posts/show.html.slim_spec.rb | 16 ++ 10 files changed, 378 insertions(+) create mode 100644 spec/controllers/admin/better_together/posts_controller_spec.rb create mode 100644 spec/controllers/better_together/posts_controller_spec.rb create mode 100644 spec/requests/better_together/better_together_posts_spec.rb create mode 100644 spec/routing/admin/better_together/posts_routing_spec.rb.tmp create mode 100644 spec/routing/better_together/posts_routing_spec.rb.tmp create mode 100644 spec/views/admin/better_together/posts/edit.html.slim_spec.rb create mode 100644 spec/views/admin/better_together/posts/index.html.slim_spec.rb create mode 100644 spec/views/admin/better_together/posts/new.html.slim_spec.rb create mode 100644 spec/views/better_together/posts/index.html.slim_spec.rb create mode 100644 spec/views/better_together/posts/show.html.slim_spec.rb diff --git a/spec/controllers/admin/better_together/posts_controller_spec.rb b/spec/controllers/admin/better_together/posts_controller_spec.rb new file mode 100644 index 00000000..f920bfaf --- /dev/null +++ b/spec/controllers/admin/better_together/posts_controller_spec.rb @@ -0,0 +1,144 @@ +# require 'rails_helper' + +# # This spec was generated by rspec-rails when you ran the scaffold generator. +# # It demonstrates how one might use RSpec to specify the controller code that +# # was generated by Rails when you ran the scaffold generator. +# # +# # It assumes that the implementation code is generated by the rails scaffold +# # generator. If you are using any extension libraries to generate different +# # controller code, this generated spec may or may not pass. +# # +# # It only uses APIs available in rails and/or rspec-rails. There are a number +# # of tools you can use to make these specs even more expressive, but we're +# # sticking to rails and rspec-rails APIs to keep things simple and stable. +# # +# # Compared to earlier versions of this generator, there is very limited use of +# # stubs and message expectations in this spec. Stubs are only used when there +# # is no simpler way to get a handle on the object needed for the example. +# # Message expectations are only used when there is no simpler way to specify +# # that an instance is receiving a specific message. +# # +# # Also compared to earlier versions of this generator, there are no longer any +# # expectations of assigns and templates rendered. These features have been +# # removed from Rails core in Rails 5, but can be added back in via the +# # `rails-controller-testing` gem. + +# RSpec.describe Admin::BetterTogether::PostsController, type: :controller do + +# # This should return the minimal set of attributes required to create a valid +# # BetterTogether::Post. As you add validations to BetterTogether::Post, be sure to +# # adjust the attributes here as well. +# let(:valid_attributes) { +# { +# title: 'My First Post', +# content: 'My first content' +# } +# } + +# let(:invalid_attributes) { +# skip("Add a hash of attributes invalid for your model") +# } + +# # This should return the minimal set of values that should be in the session +# # in order to pass any filters (e.g. authentication) defined in +# # BetterTogether::PostsController. Be sure to keep this updated too. +# let(:valid_session) { {} } + +# describe "GET #index" do +# it "returns a success response" do +# BetterTogether::Post.create! valid_attributes +# get :index, params: {}, session: valid_session +# expect(response).to be_successful +# end +# end + +# describe "GET #show" do +# it "returns a success response" do +# post = BetterTogether::Post.create! valid_attributes +# get :show, params: {id: post.to_param}, session: valid_session +# expect(response).to be_successful +# end +# end + +# describe "GET #new" do +# it "returns a success response" do +# get :new, params: {}, session: valid_session +# expect(response).to be_successful +# end +# end + +# describe "GET #edit" do +# it "returns a success response" do +# post = BetterTogether::Post.create! valid_attributes +# get :edit, params: {id: post.to_param}, session: valid_session +# expect(response).to be_successful +# end +# end + +# describe "POST #create" do +# context "with valid params" do +# it "creates a new BetterTogether::Post" do +# expect { +# post :create, params: {better_together_post: valid_attributes}, session: valid_session +# }.to change(BetterTogether::Post, :count).by(1) +# end + +# it "redirects to the created better_together_post" do +# post :create, params: {better_together_post: valid_attributes}, session: valid_session +# expect(response).to redirect_to([:admin, BetterTogether::Post.last]) +# end +# end + +# context "with invalid params" do +# it "returns a success response (i.e. to display the 'new' template)" do +# post :create, params: {better_together_post: invalid_attributes}, session: valid_session +# expect(response).to be_successful +# end +# end +# end + +# describe "PUT #update" do +# context "with valid params" do +# let(:new_attributes) { +# skip("Add a hash of attributes valid for your model") +# } + +# it "updates the requested better_together_post" do +# post = BetterTogether::Post.create! valid_attributes +# put :update, params: {id: post.to_param, better_together_post: new_attributes}, session: valid_session +# post.reload +# skip("Add assertions for updated state") +# end + +# it "redirects to the better_together_post" do +# post = BetterTogether::Post.create! valid_attributes +# put :update, params: {id: post.to_param, better_together_post: valid_attributes}, session: valid_session +# expect(response).to redirect_to(post) +# end +# end + +# context "with invalid params" do +# it "returns a success response (i.e. to display the 'edit' template)" do +# post = BetterTogether::Post.create! valid_attributes +# put :update, params: {id: post.to_param, better_together_post: invalid_attributes}, session: valid_session +# expect(response).to be_successful +# end +# end +# end + +# describe "DELETE #destroy" do +# it "destroys the requested better_together_post" do +# post = BetterTogether::Post.create! valid_attributes +# expect { +# delete :destroy, params: {id: post.to_param}, session: valid_session +# }.to change(BetterTogether::Post, :count).by(-1) +# end + +# it "redirects to the better_together_posts list" do +# post = BetterTogether::Post.create! valid_attributes +# delete :destroy, params: {id: post.to_param}, session: valid_session +# expect(response).to redirect_to(better_together_posts_url) +# end +# end + +# end diff --git a/spec/controllers/better_together/posts_controller_spec.rb b/spec/controllers/better_together/posts_controller_spec.rb new file mode 100644 index 00000000..32c3e8a5 --- /dev/null +++ b/spec/controllers/better_together/posts_controller_spec.rb @@ -0,0 +1,62 @@ +# require 'rails_helper' + +# # This spec was generated by rspec-rails when you ran the scaffold generator. +# # It demonstrates how one might use RSpec to specify the controller code that +# # was generated by Rails when you ran the scaffold generator. +# # +# # It assumes that the implementation code is generated by the rails scaffold +# # generator. If you are using any extension libraries to generate different +# # controller code, this generated spec may or may not pass. +# # +# # It only uses APIs available in rails and/or rspec-rails. There are a number +# # of tools you can use to make these specs even more expressive, but we're +# # sticking to rails and rspec-rails APIs to keep things simple and stable. +# # +# # Compared to earlier versions of this generator, there is very limited use of +# # stubs and message expectations in this spec. Stubs are only used when there +# # is no simpler way to get a handle on the object needed for the example. +# # Message expectations are only used when there is no simpler way to specify +# # that an instance is receiving a specific message. +# # +# # Also compared to earlier versions of this generator, there are no longer any +# # expectations of assigns and templates rendered. These features have been +# # removed from Rails core in Rails 5, but can be added back in via the +# # `rails-controller-testing` gem. + +# RSpec.describe BetterTogether::PostsController, type: :controller do + +# # This should return the minimal set of attributes required to create a valid +# # BetterTogether::Post. As you add validations to BetterTogether::Post, be sure to +# # adjust the attributes here as well. +# let(:valid_attributes) { +# { +# title: 'My First Post', +# content: 'My first content' +# } +# } + +# let(:invalid_attributes) { +# skip("Add a hash of attributes invalid for your model") +# } + +# # This should return the minimal set of values that should be in the session +# # in order to pass any filters (e.g. authentication) defined in +# # BetterTogether::PostsController. Be sure to keep this updated too. +# let(:valid_session) { {} } + +# describe "GET #index" do +# it "returns a success response" do +# BetterTogether::Post.create! valid_attributes +# get :index, params: {}, session: valid_session +# expect(response).to be_successful +# end +# end + +# describe "GET #show" do +# it "returns a success response" do +# post = BetterTogether::Post.create! valid_attributes +# get :show, params: {id: post.to_param}, session: valid_session +# expect(response).to be_successful +# end +# end +# end diff --git a/spec/requests/better_together/better_together_posts_spec.rb b/spec/requests/better_together/better_together_posts_spec.rb new file mode 100644 index 00000000..c8b2861c --- /dev/null +++ b/spec/requests/better_together/better_together_posts_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "BetterTogether::Posts", type: :request do + describe "GET /better_together_posts" do + it "works! (now write some real specs)" do + get better_together_posts_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/admin/better_together/posts_routing_spec.rb.tmp b/spec/routing/admin/better_together/posts_routing_spec.rb.tmp new file mode 100644 index 00000000..8f90be5f --- /dev/null +++ b/spec/routing/admin/better_together/posts_routing_spec.rb.tmp @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe Admin::BetterTogether::PostsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/admin/posts").to route_to("admin/better_together/posts#index") + end + + it "routes to #new" do + expect(:get => "/admin/posts/new").to route_to("admin/better_together/posts#new") + end + + it "routes to #show" do + expect(:get => "/admin/posts/1").to route_to("admin/better_together/posts#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/admin/posts/1/edit").to route_to("admin/better_together/posts#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/admin/posts").to route_to("admin/better_together/posts#create") + end + + it "routes to #update via PUT" do + expect(:put => "/admin/posts/1").to route_to("admin/better_together/posts#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/admin/posts/1").to route_to("admin/better_together/posts#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/admin/posts/1").to route_to("admin/better_together/posts#destroy", :id => "1") + end + end +end diff --git a/spec/routing/better_together/posts_routing_spec.rb.tmp b/spec/routing/better_together/posts_routing_spec.rb.tmp new file mode 100644 index 00000000..16e4b454 --- /dev/null +++ b/spec/routing/better_together/posts_routing_spec.rb.tmp @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe BetterTogether::PostsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/posts").to route_to("better_together/posts#index") + end + + it "routes to #show" do + expect(:get => "/posts/1").to route_to("better_together/posts#show", :id => "1") + end + + it "does not route to #new" do + expect(:get => "/posts/new").not_to route_to("better_together/posts#new") + end + + + it "does not route to #edit" do + expect(:get => "/posts/1/edit").not_to route_to("better_together/posts#edit", :id => "1") + end + + + it "does not route to #create" do + expect(:post => "/posts").not_to route_to("better_together/posts#create") + end + + it "does not route to #update via PUT" do + expect(:put => "/posts/1").not_to route_to("better_together/posts#update", :id => "1") + end + + it "does not route to #update via PATCH" do + expect(:patch => "/posts/1").not_to route_to("better_together/posts#update", :id => "1") + end + + it "does not route to #destroy" do + expect(:delete => "/posts/1").not_to route_to("better_together/posts#destroy", :id => "1") + end + end +end diff --git a/spec/views/admin/better_together/posts/edit.html.slim_spec.rb b/spec/views/admin/better_together/posts/edit.html.slim_spec.rb new file mode 100644 index 00000000..571c15ba --- /dev/null +++ b/spec/views/admin/better_together/posts/edit.html.slim_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "admin/better_together/posts/edit", type: :view do + before(:each) do + @better_together_post = assign(:better_together_post, create(:better_together_post)) + end + + it "renders the edit better_together_post form" do + render + + assert_select "form[action=?][method=?]", admin_better_together_post_path(@better_together_post), "post" do + + assert_select "input[name=?]", "better_together_post[title]" + assert_select "textarea[name=?]", "better_together_post[content]" + assert_select "input[name=?]", "better_together_post[slug]" + end + end +end diff --git a/spec/views/admin/better_together/posts/index.html.slim_spec.rb b/spec/views/admin/better_together/posts/index.html.slim_spec.rb new file mode 100644 index 00000000..357fafa1 --- /dev/null +++ b/spec/views/admin/better_together/posts/index.html.slim_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe "admin/better_together/posts/index", type: :view do + before(:each) do + create_list(:better_together_post, 2) + end + + # it "renders a list of better_together/posts" do + # render + # assert_select "tr>td", :text => "Bt".to_s, :count => 2 + # end +end diff --git a/spec/views/admin/better_together/posts/new.html.slim_spec.rb b/spec/views/admin/better_together/posts/new.html.slim_spec.rb new file mode 100644 index 00000000..bcb1735e --- /dev/null +++ b/spec/views/admin/better_together/posts/new.html.slim_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "admin/better_together/posts/new", type: :view do + before(:each) do + assign(:better_together_post, create(:better_together_post)) + end + + # it "renders new better_together_post form" do + # render + + # assert_select "form[action=?][method=?]", admin_better_together_posts_path, "post" do + + # assert_select "input[name=?]", "better_together_post[title]" + # assert_select "textarea[name=?]", "better_together_post[content]" + # assert_select "input[name=?]", "better_together_post[slug]" + # end + # end +end diff --git a/spec/views/better_together/posts/index.html.slim_spec.rb b/spec/views/better_together/posts/index.html.slim_spec.rb new file mode 100644 index 00000000..a7ecf3d6 --- /dev/null +++ b/spec/views/better_together/posts/index.html.slim_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "better_together/posts/index", type: :view do + before(:each) do + assign(:better_together_posts, [ + BetterTogether::Post.create!( + title: 'My First Post', + content: 'My Seocnd Content' + ), + BetterTogether::Post.create!( + title: 'My First Post', + content: 'My Seocnd Content' + ) + ]) + end + + it "renders a list of better_together/posts" do + render + assert_select "h3.post-title", :count => 2 + end +end diff --git a/spec/views/better_together/posts/show.html.slim_spec.rb b/spec/views/better_together/posts/show.html.slim_spec.rb new file mode 100644 index 00000000..7319fe52 --- /dev/null +++ b/spec/views/better_together/posts/show.html.slim_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "better_together/posts/show", type: :view do + before(:each) do + @better_together_post = assign(:better_together_post, BetterTogether::Post.create!( + :bt_id => "Bt", + title: 'My First Post', + content: 'My First Content' + )) + end + + it "renders its title" do + render + expect(rendered).to match(/My First Post/) + end +end