Skip to content

Commit d9dbbdb

Browse files
committed
add missing tests for the component generator options
--namepsace --haml and --scss
1 parent 59b4758 commit d9dbbdb

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

lib/generators/matestack/component/component_generator.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ def namespace
1212
options[:namespace]
1313
end
1414

15-
def create_component
16-
@dynamic = options[:dynamic]
15+
def dynamic
16+
options[:dynamic]
17+
end
1718

19+
def create_component
1820
# Future: Check for matestack-compatible namespacing!
1921

2022
template 'app/matestack/components/%namespace%/%file_name%.rb.tt'

lib/generators/matestack/component/templates/app/matestack/components/%namespace%/%file_name%.js.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Require your custom component in your application.js before usage
22
// Place it below "//= require matestack-ui-core" using the following line:
3-
//= require <% unless @namespace.nil? %><%= @namespace %>/<% end %><%= file_name %>
3+
//= require <% unless namespace.nil? %><%= namespace %>/<% end %><%= file_name %>
44

5-
MatestackUiCore.Vue.component('custom<% unless @namespace.nil? %>-<%= @namespace %><% end %>-<%= file_name %>', {
5+
MatestackUiCore.Vue.component('custom<% unless namespace.nil? %>-<%= namespace %><% end %>-<%= file_name %>', {
66
mixins: [MatestackUiCore.componentMixin],
77
data: function() {
88
return {

lib/generators/matestack/component/templates/app/matestack/components/%namespace%/%file_name%.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Components::<% unless @namespace.nil? %><%= @namespace.camelize %>::<% end %><%= class_name %> < Matestack::Ui::<% if @dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
1+
class Components::<% unless namespace.nil? %><%= namespace.camelize %>::<% end %><%= class_name %> < Matestack::Ui::<% if dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
22
def prepare
33
# DB queries and API calls go here
44
end

spec/lib/generators/matestack/component/component_generator_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,27 @@
3030
assert_file "app/matestack/components/example_component.js", /custom-example_component\b/
3131
end
3232

33+
it "creates a haml file with the haml option" do
34+
run_generator %w(example_component --haml)
35+
36+
assert_file "app/matestack/components/example_component.haml", %r{.example_component{@tag_attributes}}
37+
assert_file "app/matestack/components/example_component.haml", /This is your custom ExampleComponent component/
38+
end
39+
40+
it "creates a scss file with the scss option" do
41+
run_generator %w(example_component --scss)
42+
43+
assert_file "app/matestack/components/example_component.scss", %r{// your styles for the component ExampleComponent go here}
44+
end
45+
46+
it "creates a custom component in the right namespace" do
47+
run_generator %w(example_component --namespace example_namespace --dynamic --scss --haml)
48+
49+
assert_file "app/matestack/components/example_namespace/example_component.rb", /class Components::ExampleNamespace::ExampleComponent < Matestack::Ui::DynamicComponent/
50+
assert_file "app/matestack/components/example_namespace/example_component.js", /custom-example_namespace-example_component/
51+
assert_file "app/matestack/components/example_namespace/example_component.js", %r{require example_namespace/example_component}
52+
assert_file "app/matestack/components/example_namespace/example_component.haml"
53+
assert_file "app/matestack/components/example_namespace/example_component.scss"
54+
end
55+
3356
end

0 commit comments

Comments
 (0)