jbuilder_rspec_generator 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b950f7c524fad22f56605af7dee4bf313b6d53a
4
- data.tar.gz: a7dcb94c18ba1581a64ce65761f8e387d76f2e49
3
+ metadata.gz: a89167a84eeebe582e3c88f3f419a03581e65032
4
+ data.tar.gz: 8750eeb889593a5fd2eab307dcbc36d113fc3bd1
5
5
  SHA512:
6
- metadata.gz: f207426438154c4669561903fad9f4746d2f4fd4cb1b578a0ee16c72035c149391c359312f0412c5aac8bfc0a24608480788022c54c18dd9df9c830f4b1fcc49
7
- data.tar.gz: 504a0a60ad624d4086f80386496086111c38eeff8ac3a54dc81569b6204af30bc51f57ae7654ee8ad8efcc2f59aab48d187e3ded81388fdc47b7f1c1ce8c93be
6
+ metadata.gz: 33117bdbe977770e3bce23b1378fdc5950c01a4098eafea83ce92bfe4c09c349363e68d7eee2e4879d8b64afbf12aef971aab66ec6428615bfbdc7a71bec4878
7
+ data.tar.gz: 2f1889f3737d46f27aa616b923a950662283c16324705b9297fd7cd05a97b3249518408aee6326e3f85355b9049f73802b71e781538f88c2754e1d47ab084f45
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: jbuilder_rspec_generator 1.1.0 ruby lib
5
+ # stub: jbuilder_rspec_generator 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "jbuilder_rspec_generator"
9
- s.version = "1.1.0"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Dmitri Koulikoff"]
14
- s.date = "2015-06-14"
14
+ s.date = "2016-03-22"
15
15
  s.description = "Generates RSpecs for jbuilder templates"
16
16
  s.email = "dima@koulikoff.ru"
17
17
  s.extra_rdoc_files = [
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  ]
37
37
  s.homepage = "http://github.com/dima4p/jbuilder_rspec_generator"
38
38
  s.licenses = ["MIT"]
39
- s.rubygems_version = "2.2.2"
39
+ s.rubygems_version = "2.5.1"
40
40
  s.summary = "RSpecs for jbuilder templates"
41
41
 
42
42
  if s.respond_to? :specification_version then
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
  <% end -%>
6
6
 
7
7
  <% open_attributes = attributes.reject(&:password_digest?) -%>
8
+ <% links = open_attributes.select{|a| [:belongs_to, :references].include? a.type} -%>
8
9
  describe "<%= ns_table_name %>/index.json.jbuilder", type: :view do
9
10
  before(:each) do
10
11
  <% if Rails.application.config.generators.options[:rails][:cancan] -%>
@@ -20,6 +21,7 @@ describe "<%= ns_table_name %>/index.json.jbuilder", type: :view do
20
21
  )
21
22
  <% end -%>
22
23
  assign :<%= table_name %>, [@<%= ns_file_name %>, @<%= ns_file_name %>]
24
+ render
23
25
  end
24
26
 
25
27
  attributes = %w[
@@ -29,21 +31,48 @@ describe "<%= ns_table_name %>/index.json.jbuilder", type: :view do
29
31
  <% end -%>
30
32
  url
31
33
  ]
34
+ <% if links.present? -%>
35
+ complex = %w[
36
+ <% for attribute in links -%>
37
+ <%= attribute.name %>
38
+ <% end -%>
39
+ ]
40
+ <% for attribute in links -%>
41
+ <%= attribute.name %>_attributes = %w[
42
+ id
43
+ name
44
+ url
45
+ ]
46
+ <% end -%>
47
+ <% end -%>
32
48
 
33
49
  it "renders a list of <%= table_name %> as json with following attributes: #{attributes.join(', ')}" do
34
- render
35
-
36
50
  hash = MultiJson.load rendered
37
51
  expect(hash.first).to eq(hash = hash.last)
38
52
  expect(hash.keys.sort).to eq attributes.sort
53
+ <% if links.present? -%>
54
+ expected = @<%= ns_file_name %>.attributes.slice *(attributes - complex)
55
+ <% else -%>
39
56
  expected = @<%= ns_file_name %>.attributes.slice *attributes
57
+ <% end -%>
40
58
  expected = MultiJson.load MultiJson.dump expected
41
59
  expected['url'] = <%= ns_file_name %>_url(@<%= ns_file_name %>, format: 'json')
60
+ <% if links.present? -%>
61
+ expect(hash.except! *complex).to eq expected
62
+ <% else -%>
42
63
  expect(hash).to eq expected
43
- # expect(hash['id']).to eq @<%= ns_file_name %>.id.to_s
44
- <% for attribute in open_attributes -%>
45
- # expect(hash['<%= attribute.name %>']).to eq @<%= ns_file_name %>.<%= attribute.name %>.to_s
46
64
  <% end -%>
47
- # expect(hash['url']).to eq <%= ns_file_name %>_url(@<%= ns_file_name %>, format: 'json')
48
65
  end
66
+ <% for attribute in links -%>
67
+
68
+ it "renders <%= attribute.name %> of the <%= table_name %> with the following attributes: #{<%= attribute.name %>_attributes.join(', ')}" do
69
+ hash = MultiJson.load(rendered).last
70
+ hash = hash['<%= attribute.name %>']
71
+ expect(hash.keys.sort).to eq <%= attribute.name %>_attributes.sort
72
+ expected = @<%= ns_file_name %>.<%= attribute.name %>.attributes.slice *<%= attribute.name %>_attributes
73
+ expected = MultiJson.load MultiJson.dump expected
74
+ expected['url'] = <%= attribute.name %>_url(@<%= ns_file_name %>.<%= attribute.name %>, format: 'json')
75
+ expect(hash).to eq expected
76
+ end
77
+ <% end -%>
49
78
  end
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
  <% end -%>
6
6
 
7
7
  <% open_attributes = attributes.reject(&:password_digest?) -%>
8
+ <% links = open_attributes.select{|a| [:belongs_to, :references].include? a.type} -%>
8
9
  describe "<%= ns_table_name %>/show.json.jbuilder", type: :view do
9
10
  before(:each) do
10
11
  <% if Rails.application.config.generators.options[:rails][:cancan] -%>
@@ -21,6 +22,7 @@ describe "<%= ns_table_name %>/show.json.jbuilder", type: :view do
21
22
  ))
22
23
  <% end -%>
23
24
  <% end -%>
25
+ render
24
26
  end
25
27
 
26
28
  attributes = %w[
@@ -31,20 +33,46 @@ describe "<%= ns_table_name %>/show.json.jbuilder", type: :view do
31
33
  created_at
32
34
  updated_at
33
35
  ]
36
+ <% if links.present? -%>
37
+ complex = %w[
38
+ <% for attribute in links -%>
39
+ <%= attribute.name %>
40
+ <% end -%>
41
+ ]
42
+ <% for attribute in links -%>
43
+ <%= attribute.name %>_attributes = %w[
44
+ id
45
+ name
46
+ url
47
+ ]
48
+ <% end -%>
49
+ <% end -%>
34
50
 
35
51
  it "renders the following attributes of <%= ns_file_name %>: #{attributes.join(', ')} as json" do
36
- render
37
-
38
52
  hash = MultiJson.load rendered
39
53
  expect(hash.keys.sort).to eq attributes.sort
54
+ <% if links.present? -%>
55
+ expected = @<%= ns_file_name %>.attributes.slice *(attributes - complex)
56
+ <% else -%>
40
57
  expected = @<%= ns_file_name %>.attributes.slice *attributes
58
+ <% end -%>
41
59
  expected = MultiJson.load MultiJson.dump expected
60
+ <% if links.present? -%>
61
+ expect(hash.except! *complex).to eq expected
62
+ <% else -%>
42
63
  expect(hash).to eq expected
43
- # expect(hash['id']).to eq @<%= ns_file_name %>.id.to_s
44
- <% for attribute in open_attributes -%>
45
- # expect(hash['<%= attribute.name %>']).to eq @<%= ns_file_name %>.<%= attribute.name %>.to_s
46
64
  <% end -%>
47
- # expect(hash['created_at']).to eq @<%= ns_file_name %>.created_at.to_s
48
- # expect(hash['updated_at']).to eq @<%= ns_file_name %>.updated_at.to_s
49
65
  end
66
+ <% for attribute in links -%>
67
+
68
+ it "renders <%= attribute.name %> of the <%= table_name %> with the following attributes: #{<%= attribute.name %>_attributes.join(', ')}" do
69
+ hash = MultiJson.load(rendered)
70
+ hash = hash['<%= attribute.name %>']
71
+ expect(hash.keys.sort).to eq <%= attribute.name %>_attributes.sort
72
+ expected = @<%= ns_file_name %>.<%= attribute.name %>.attributes.slice *<%= attribute.name %>_attributes
73
+ expected = MultiJson.load MultiJson.dump expected
74
+ expected['url'] = <%= attribute.name %>_url(@<%= ns_file_name %>.<%= attribute.name %>, format: 'json')
75
+ expect(hash).to eq expected
76
+ end
77
+ <% end -%>
50
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder_rspec_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Koulikoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.2.2
139
+ rubygems_version: 2.5.1
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: RSpecs for jbuilder templates