Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-rails-rspec
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aman Sharma
react-rails-rspec
Commits
d41bb425
Commit
d41bb425
authored
Oct 03, 2020
by
Abhisarika Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
worked on model using factories,api, controller & features testcases
parent
87e27025
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
151 additions
and
9 deletions
+151
-9
books_controller.rb
app/controllers/api/v1/books_controller.rb
+0
-1
AddBooks.jsx
app/javascript/components/library/AddBooks.jsx
+2
-2
BookDetails.jsx
app/javascript/components/library/BookDetails.jsx
+33
-1
BooksList.jsx
app/javascript/components/library/BooksList.jsx
+3
-0
Library.jsx
app/javascript/components/library/Library.jsx
+4
-0
book.rb
spec/factories/book.rb
+8
-0
homepage._spec.rb
spec/features/homepage._spec.rb
+2
-0
library_spec.rb
spec/features/library_spec.rb
+13
-0
book_spec.rb
spec/models/book_spec.rb
+58
-1
rails_helper.rb
spec/rails_helper.rb
+1
-0
book_request_spec.rb
spec/requests/api/v1/book_request_spec.rb
+27
-4
No files found.
app/controllers/api/v1/books_controller.rb
View file @
d41bb425
...
...
@@ -25,7 +25,6 @@ class Api::V1::BooksController < ApplicationController
def
destroy
puts
"hhhgh"
book
&
.
destroy
render
json:
{
message:
'Book deleted!'
}
end
...
...
app/javascript/components/library/AddBooks.jsx
View file @
d41bb425
...
...
@@ -17,7 +17,7 @@ class AddBooks extends Component {
}
goBack
()
{
Router
.
history
.
goBack
(
);
this
.
props
.
history
.
go
(
-
1
);
}
saveBook
(
event
)
{
...
...
@@ -108,7 +108,7 @@ class AddBooks extends Component {
</
form
>
</
div
>
<
button
onClick=
{
this
.
goBack
}
>
Go Back
</
button
>
<
button
onClick=
{
this
.
goBack
}
className=
"btn btn-link"
>
Go Back
</
button
>
<
Link
to=
"/"
className=
"btn btn-link"
>
Home
</
Link
>
...
...
app/javascript/components/library/BookDetails.jsx
View file @
d41bb425
...
...
@@ -6,6 +6,8 @@ class BookDetails extends Component{
super
(
props
);
this
.
setState
=
this
.
setState
.
bind
(
this
)
this
.
deleteBook
=
this
.
deleteBook
.
bind
(
this
)
this
.
updateBookDetails
=
this
.
updateBookDetails
(
this
)
this
.
getToken
=
this
.
getToken
.
bind
(
this
)
this
.
state
=
{
book
:
{}
}
}
...
...
@@ -53,6 +55,32 @@ class BookDetails extends Component{
.
catch
(
error
=>
console
.
log
(
error
.
message
));
}
updateBookDetails
(){
const
id
=
this
.
props
.
location
.
search
.
split
(
'?'
)[
1
].
split
(
'='
)[
1
]
const
url
=
`/api/v1/book/update/
${
id
}
`
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
fetch
(
url
,
{
method
:
"GET"
,
headers
:
{
"X-CSRF-Token"
:
token
,
"Content-Type"
:
"application/json"
}
})
.
then
(
response
=>
{
if
(
response
.
ok
)
{
return
response
.
json
();
}
throw
new
Error
(
"Network response was not ok."
);
})
.
then
((
response
)
=>
this
.
setState
({
book
:
response
}))
.
catch
(
error
=>
console
.
log
(
error
.
message
));
}
getToken
(){
return
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
}
render
(){
const
{
book
}
=
this
.
state
return
(
...
...
@@ -65,12 +93,16 @@ class BookDetails extends Component{
<
div
className=
"py-5"
>
<
main
className=
"container"
>
<
div
className=
"text-right mb-3"
>
<
Link
to=
"/"
className=
"btn btn-link"
>
Home
</
Link
>
<
button
onClick=
{
this
.
props
.
history
.
goBack
}
className=
"btn btn-link"
></
button
>
</
div
>
<
div
className=
"row"
>
<
div
>
{
book
.
name
}
</
div
>
<
div
>
{
book
.
writterName
}
</
div
>
<
div
>
{
book
.
courseName
}
</
div
>
<
button
>
edit
</
button
>
{
/* <button onClick={this.updateBookDetails}>edit</button> */
}
<
button
onClick=
{
this
.
deleteBook
}
>
delete
</
button
>
</
div
>
</
main
>
...
...
app/javascript/components/library/BooksList.jsx
View file @
d41bb425
...
...
@@ -111,6 +111,7 @@ class BooksList extends Component{
name=
"name"
id=
"name"
className=
"form-control"
placeholder=
"search by bookname"
/>
<
button
onClick=
{
this
.
searchByBookName
}
>
search
</
button
>
</
div
>
...
...
@@ -120,6 +121,8 @@ class BooksList extends Component{
<
Link
to=
"/"
className=
"btn btn-link"
>
Home
</
Link
>
<
button
className=
"btn btn-link"
onClick=
{
this
.
props
.
history
.
goBack
}
>
Go Back
</
button
>
{
/* <Link to={this.props.history.goBack} className="btn btn-link"></Link> */
}
</
main
>
</
div
>
</>
...
...
app/javascript/components/library/Library.jsx
View file @
d41bb425
...
...
@@ -13,7 +13,11 @@ class Library extends Component {
<
main
className=
"container"
>
<
div
className=
"text-right mb-3"
>
Manage your books
</
div
>
<
Link
to=
"/booksList"
className=
"btn btn-link"
>
view all books
</
Link
>
<
Link
to=
"/addBooks"
className=
"btn btn-link"
>
create books
</
Link
>
...
...
spec/factories/book.rb
0 → 100644
View file @
d41bb425
FactoryBot
.
define
do
factory
:book
,
class:
Book
do
name
{
Faker
::
Name
.
name
}
writterName
{
Faker
::
Name
.
name
}
courseName
{
Faker
::
Name
.
name
}
end
end
\ No newline at end of file
spec/features/homepage._spec.rb
View file @
d41bb425
...
...
@@ -3,4 +3,5 @@ describe "GET '/' - from API", :type => :feature do
visit
(
'http://localhost:3000/'
)
expect
(
page
).
to
have_title
"RailsReactRecipe"
end
end
\ No newline at end of file
spec/features/library_spec.rb
0 → 100644
View file @
d41bb425
require
'rails_helper'
RSpec
.
feature
"Libraries"
,
type: :feature
do
context
"Adding books"
do
before
do
visit
'http://localhost:3000/addBooks'
end
scenario
"book should be added"
,
:js
do
expect
(
page
).
to
have_text
(
"ADD BOOk"
)
end
end
end
spec/models/book_spec.rb
View file @
d41bb425
require
'rails_helper'
RSpec
.
describe
Book
,
type: :model
do
pending
"add some examples to (or delete)
#{
__FILE__
}
"
describe
"Test Book Model Validation"
do
let
(
:book
)
{
build
(
:book
)
}
it
'should validate if bookname is nil'
do
book
.
name
=
nil
expect
(
book
.
save
).
to
eq
(
false
)
end
it
'should validate if writter name is nil'
do
book
.
writterName
=
nil
expect
(
book
.
save
).
to
be
(
false
)
end
it
'should validate if course name is nil'
do
book
.
courseName
=
nil
expect
(
book
.
save
).
to
eq
(
false
)
end
it
'should valid if book model fields are nil'
do
book
=
Book
.
new
(
name
:'Math'
,
writterName:
'jhjh'
,
courseName:
"nil"
)
expect
(
book
).
to
be_valid
end
it
'bookname & writter name shold not be same '
do
expect
(
book
.
name
).
to_not
be
(
book
.
writterName
)
end
it
"is not equal to another string of a different value"
do
expect
(
"this string"
).
not_to
eql
(
"a different string"
)
end
it
"is not equal to a float of the same value"
do
expect
(
5
).
not_to
eql
(
5.0
)
end
it
"is not equal to a float of the same value"
do
puts
book
.
name
puts
book
.
writterName
puts
book
.
courseName
# expect(book.name).to be==book.courseName
end
context
'Employee Table Operations Test Case'
do
it
'save book'
do
book
=
Book
.
new
(
name
:'Math'
,
writterName:
'jhjh'
,
courseName:
"nil"
).
save
expect
(
book
).
to
eq
(
true
)
end
it
'delete book'
do
book
=
Book
.
delete
(
name
:'Math'
)
expect
(
book
).
to
eq
(
0
)
end
end
end
end
spec/rails_helper.rb
View file @
d41bb425
...
...
@@ -5,6 +5,7 @@ require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort
(
"The Rails environment is running in production mode!"
)
if
Rails
.
env
.
production?
require
'rspec/rails'
require
'capybara/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
...
...
spec/requests/api/v1/book_request_spec.rb
View file @
d41bb425
...
...
@@ -4,14 +4,14 @@ RSpec.describe "Api::V1::Books", type: :request do
describe
"GET /index"
do
it
"returns http success"
do
get
"/api/v1/book/index"
get
"/api/v1/book
s
/index"
expect
(
response
).
to
have_http_status
(
:success
)
end
end
describe
"
GE
T /create"
do
describe
"
POS
T /create"
do
it
"returns http success"
do
get
"/api/v1/book/create"
get
"/api/v1/book
s
/create"
expect
(
response
).
to
have_http_status
(
:success
)
end
end
...
...
@@ -23,11 +23,34 @@ RSpec.describe "Api::V1::Books", type: :request do
end
end
describe
"
GET
/destroy"
do
describe
"
DELETE
/destroy"
do
it
"returns http success"
do
get
"/api/v1/book/destroy"
expect
(
response
).
to
have_http_status
(
:success
)
end
end
describe
"GET /search"
do
it
"returns http success"
do
get
"/api/v1/book/search"
expect
(
response
).
to
have_http_status
(
:success
)
end
end
describe
"GET /update"
do
it
"returns http success"
do
get
"/api/v1/book/update"
expect
(
response
).
to
have_http_status
(
:success
)
end
end
# describe "Books" do
# describe 'routing' do
# it 'routes GET /book to books#show' do
# # get("/book").should route_to("books#index")
# expect(get: '/book').to route_to(controller: 'books', action: 'show')
# end
# end
# end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment