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 blog posts #155

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
144 changes: 144 additions & 0 deletions spec/controllers/admin/better_together/posts_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions spec/controllers/better_together/posts_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions spec/requests/better_together/better_together_posts_spec.rb
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions spec/routing/admin/better_together/posts_routing_spec.rb.tmp
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions spec/routing/better_together/posts_routing_spec.rb.tmp
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions spec/views/admin/better_together/posts/edit.html.slim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/views/admin/better_together/posts/index.html.slim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions spec/views/admin/better_together/posts/new.html.slim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions spec/views/better_together/posts/index.html.slim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/views/better_together/posts/show.html.slim_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading