Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
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
open-source
shotengai
Commits
13a79c3d
Commit
13a79c3d
authored
Aug 31, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec generator into controller generator
parent
b0dc8cc4
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
31 additions
and
40 deletions
+31
-40
controllers_generator.rb
lib/generators/shotengai/controllers_generator.rb
+17
-0
spec_generator.rb
lib/generators/shotengai/spec_generator.rb
+0
-26
merchants.rb
lib/generators/templates/spec/factories/merchants.rb
+1
-1
shotengai_orders.rb
lib/generators/templates/spec/factories/shotengai_orders.rb
+1
-1
shotengai_products.rb
...generators/templates/spec/factories/shotengai_products.rb
+1
-1
shotengai_series.rb
lib/generators/templates/spec/factories/shotengai_series.rb
+1
-1
shotengai_snapshots.rb
...enerators/templates/spec/factories/shotengai_snapshots.rb
+1
-1
users.rb
lib/generators/templates/spec/factories/users.rb
+1
-1
order_spec.rb
...generators/templates/spec/requests/customer/order_spec.rb
+1
-1
product_series_spec.rb
...s/templates/spec/requests/customer/product_series_spec.rb
+1
-1
product_snapshot_spec.rb
...templates/spec/requests/customer/product_snapshot_spec.rb
+1
-1
product_spec.rb
...nerators/templates/spec/requests/customer/product_spec.rb
+1
-1
order_spec.rb
...generators/templates/spec/requests/merchant/order_spec.rb
+1
-1
product_series_spec.rb
...s/templates/spec/requests/merchant/product_series_spec.rb
+1
-1
product_snapshot_spec.rb
...templates/spec/requests/merchant/product_snapshot_spec.rb
+1
-1
product_spec.rb
...nerators/templates/spec/requests/merchant/product_spec.rb
+1
-1
No files found.
lib/generators/shotengai/controllers_generator.rb
View file @
13a79c3d
...
@@ -54,12 +54,29 @@ module Shotengai
...
@@ -54,12 +54,29 @@ module Shotengai
"app/controllers/
#{
@namespace
}
/
#{
@klass_name
.
underscore
.
pluralize
}
_controller.rb"
"app/controllers/
#{
@namespace
}
/
#{
@klass_name
.
underscore
.
pluralize
}
_controller.rb"
end
end
create_routes
create_routes
create_factory
create_request_spec
require
'irb'
binding
.
irb
end
end
def
create_routes
def
create_routes
route
(
@role
==
'merchant'
?
merchant_routes
:
customer_routes
)
route
(
@role
==
'merchant'
?
merchant_routes
:
customer_routes
)
end
end
def
create_factory
Dir
[
"
#{
self
.
class
.
source_root
}
/../spec/factories/*.rb"
].
each
do
|
path
|
template
path
,
"spec/shotengai/
#{
path
.
match
(
/(.*)\/spec\/(.*)/
)[
2
]
}
"
end
end
def
create_request_spec
Dir
[
"
#{
self
.
class
.
source_root
}
/../spec/requests/
#{
@role
}
/*.rb"
].
each
do
|
path
|
template
path
,
"spec/shotengai/
#{
path
.
match
(
/(.*)\/spec\/(.*)/
)[
2
]
}
"
end
end
def
merchant_routes
def
merchant_routes
product
,
order
=
@product
.
underscore
,
@order
.
underscore
product
,
order
=
@product
.
underscore
,
@order
.
underscore
"
"
...
...
lib/generators/shotengai/spec_generator.rb
deleted
100644 → 0
View file @
b0dc8cc4
module
Shotengai
module
Generators
class
SpecGenerator
<
Rails
::
Generators
::
Base
source_root
File
.
expand_path
(
"../../templates/spec"
,
__FILE__
)
desc
"Copy swagger spec of tempalte MVC to your application."
class_option
:customer
,
type: :string
,
required:
true
,
desc:
"Customer class name"
class_option
:merchant
,
type: :string
,
required:
true
,
desc:
"Merchant class name"
class_option
:product
,
type: :string
,
required:
true
,
desc:
"Product class name"
class_option
:order
,
type: :string
,
required:
true
,
desc:
"Order class name"
def
copy_spec
@customer_class_name
,
@merchant_class_name
,
@product_class_name
,
@order_class_name
=
options
.
values_at
(
:customer
,
:merchant
,
:product
,
:order
)
Dir
[
"
#{
self
.
class
.
source_root
}
/**/*.rb"
].
each
do
|
path
|
relative_path
=
path
.
gsub
(
self
.
class
.
source_root
,
''
)
template
path
,
"spec/shotengai/
#{
relative_path
}
"
end
end
end
end
end
lib/generators/templates/spec/factories/merchants.rb
View file @
13a79c3d
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:merchant
,
'<%= @merhcant_class_name %>
'
do
factory
:merchant
,
class_name:
'
'
do
end
end
end
end
lib/generators/templates/spec/factories/shotengai_orders.rb
View file @
13a79c3d
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#
#
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:order
,
class_name:
'<%= @order
_class_name
%>'
do
factory
:order
,
class_name:
'<%= @order %>'
do
end
end
end
end
lib/generators/templates/spec/factories/shotengai_products.rb
View file @
13a79c3d
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
#
#
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:product
,
class:
'<%= @product
_class_name
%>'
do
factory
:product
,
class:
'<%= @product %>'
do
title
'Test Product Title'
title
'Test Product Title'
# status
# status
spec
{
spec
{
...
...
lib/generators/templates/spec/factories/shotengai_series.rb
View file @
13a79c3d
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#
#
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:product_series
,
class:
'<%= "#{@product
_class_name
}Series" %>'
do
factory
:product_series
,
class:
'<%= "#{@product}Series" %>'
do
original_price
100
original_price
100
price
80
price
80
stock
10
stock
10
...
...
lib/generators/templates/spec/factories/shotengai_snapshots.rb
View file @
13a79c3d
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:product_snapshot
,
class:
'<%= "#{@product
_class_name
}Snapshot" %>'
do
factory
:product_snapshot
,
class:
'<%= "#{@product}Snapshot" %>'
do
original_price
100
original_price
100
price
80
price
80
count
2
count
2
...
...
lib/generators/templates/spec/factories/users.rb
View file @
13a79c3d
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:user
,
class_name:
'
<%= @customer_class_name %>
'
do
factory
:user
,
class_name:
''
do
end
end
end
end
lib/generators/templates/spec/requests/customer/order_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
customer_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/orders"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"order"
]
do
RSpec
.
describe
"
#{
namespace
}
/orders"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"order"
]
do
before
do
before
do
@user
=
create
(
:user
)
@user
=
create
(
:user
)
...
...
lib/generators/templates/spec/requests/customer/product_series_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
customer_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/products/:product_id/product_series"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_series"
]
do
RSpec
.
describe
"
#{
namespace
}
/products/:product_id/product_series"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_series"
]
do
before
do
before
do
@products
=
create_list
(
:product
,
3
)
@products
=
create_list
(
:product
,
3
)
...
...
lib/generators/templates/spec/requests/customer/product_snapshot_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
customer_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/product_snapshots"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_snapshots"
]
do
RSpec
.
describe
"
#{
namespace
}
/product_snapshots"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_snapshots"
]
do
before
do
before
do
@products
=
create_list
(
:product
,
3
)
@products
=
create_list
(
:product
,
3
)
...
...
lib/generators/templates/spec/requests/customer/product_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
customer_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/products"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product"
]
do
RSpec
.
describe
"
#{
namespace
}
/products"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product"
]
do
before
do
before
do
class
Catalog
<
Shotengai
::
Catalog
;
end
class
Catalog
<
Shotengai
::
Catalog
;
end
...
...
lib/generators/templates/spec/requests/merchant/order_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
merchant_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/orders"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"order"
]
do
RSpec
.
describe
"
#{
namespace
}
/orders"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"order"
]
do
before
do
before
do
@products
=
create_list
(
:product
,
3
)
@products
=
create_list
(
:product
,
3
)
...
...
lib/generators/templates/spec/requests/merchant/product_series_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
merchant_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/products/:product_id/product_series"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_series"
]
do
RSpec
.
describe
"
#{
namespace
}
/products/:product_id/product_series"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_series"
]
do
before
do
before
do
@clothes
=
Catalog
.
create!
(
name:
'衣服'
)
@clothes
=
Catalog
.
create!
(
name:
'衣服'
)
...
...
lib/generators/templates/spec/requests/merchant/product_snapshot_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
merchant_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/product_snapshots"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_snapshots"
]
do
RSpec
.
describe
"
#{
namespace
}
/product_snapshots"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_snapshots"
]
do
before
do
before
do
@products
=
create_list
(
:product
,
3
)
@products
=
create_list
(
:product
,
3
)
...
...
lib/generators/templates/spec/requests/merchant/product_spec.rb
View file @
13a79c3d
require
'swagger_helper'
require
'swagger_helper'
namespace
=
'<%= @
merchant_class_name.underscor
e %>'
namespace
=
'<%= @
namespac
e %>'
RSpec
.
describe
"
#{
namespace
}
/products"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product"
]
do
RSpec
.
describe
"
#{
namespace
}
/products"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product"
]
do
before
do
before
do
@merchant
=
create
(
:merchant
)
@merchant
=
create
(
:merchant
)
...
...
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