ember_serialize 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,29 @@ require 'test_helper'
2
2
 
3
3
  class EmberSerializeTest < ActiveSupport::TestCase
4
4
  def setup
5
+ setup_default_serializer
6
+ setup_create_serializer
7
+ end
8
+
9
+ def setup_default_serializer
10
+ return if @serializer
5
11
  Rake::Task.define_task(:environment)
6
- @rapp = Rake::Application.new
7
- # _, rargs = @rapp.parse_task_string("")
12
+ @rapp ||= Rake::Application.new
8
13
  @blank_args = Rake::TaskArguments.new([],[])
9
- @create_args = Rake::TaskArguments.new([],[':create'])
10
- @jdir = "test/dummy/app/assets/javascripts/"
11
- @mdir = "#{@jdir}models/"
12
- EmberSerialize::Serializer.javascripts_dir = @jdir
14
+ @jdir ||= "test/dummy/app/assets/javascripts/"
15
+ @mdir ||= "#{@jdir}models/"
16
+ EmberSerialize::Serializer.javascripts_dir ||= @jdir
13
17
  @serializer = EmberSerialize::Serializer.new(@blank_args)
18
+ end
19
+
20
+ def setup_create_serializer
21
+ return if @create_serializer
22
+ Rake::Task.define_task(:environment)
23
+ @rapp ||= Rake::Application.new
24
+ @create_args = Rake::TaskArguments.new([],[':create'])
25
+ @jdir ||= "test/dummy/app/assets/javascripts/"
26
+ @mdir ||= "#{@jdir}models/"
27
+ EmberSerialize::Serializer.javascripts_dir ||= @jdir
14
28
  @create_serializer = EmberSerialize::Serializer.new(@create_args)
15
29
  end
16
30
 
@@ -106,7 +120,8 @@ WITHOUTEM
106
120
  end
107
121
 
108
122
  test "parses model" do
109
- match = [["# for more details see: http://emberjs.com/guides/models/defining-models/", "", "EmberSerialize.Post = DS.Model.extend", " # ember_serialize:start", " # ember_serialize:async false", " id: DS.attr('integer'),", " title: DS.attr('string'),", " body: DS.attr('text'),", " authorDude: DS.belongsTo('user'),", " comments: DS.hasMany('comments')", " # ember_serialize:end"], 3, 10, {"id"=>" id: DS.attr('integer')", "title"=>" title: DS.attr('string')", "body"=>" body: DS.attr('text')", "authorDude"=>" authorDude: DS.belongsTo('user')", "comments"=>" comments: DS.hasMany('comments')"}, [], [], false, " "]
123
+ revert_models
124
+ match = [["# for more details see: http://emberjs.com/guides/models/defining-models/", "", "EmberSerialize.Post = DS.Model.extend", " # ember_serialize:start", " id: DS.attr('integer'),", " title: DS.attr('string'),", " body: DS.attr('text'),", " comments: DS.hasMany('comments')", " # ember_serialize:end"], 3, 8, {"id"=>" id: DS.attr('integer')", "title"=>" title: DS.attr('string')", "body"=>" body: DS.attr('text')", "comments"=>" comments: DS.hasMany('comments')"}, [], [], true, " "]
110
125
  result = @serializer.ember_model_parse "#{@mdir}post.js.coffee", Post
111
126
  assert_equal match, result, 'ember_model_parse'
112
127
  end
@@ -130,65 +145,79 @@ EmberSerialize.Post = DS.Model.extend
130
145
  assert_equal match, result, 'ember_model_build'
131
146
  end
132
147
 
148
+ test "serializes match parameter" do
149
+ clear_models
150
+ @create_serializer.serialize "Post"
151
+ assert_equal 1, Dir["#{@mdir}*.js.coffee"].length, "uses match parameter"
152
+ end
153
+
133
154
  test "serialize finds existing" do
155
+ revert_models
134
156
  prep_model 'find_existing', 'post'
135
157
  @serializer.serialize
136
158
  assert_match /find_existing/, read_model('post', /authorDude:/), 'finds existing'
137
- revert_models
138
159
  end
139
160
 
140
161
  test "serialize ignores outside" do
162
+ revert_models
141
163
  prep_model 'ignore_outside', 'post'
142
164
  @serializer.serialize
143
165
  assert_match /ignore_outside/, read_model('post', /authorDude:/), 'ignores outside'
144
- revert_models
145
166
  end
146
167
 
147
168
  test "serialize ignore setting" do
169
+ revert_models
148
170
  prep_model 'ignore', 'post'
149
171
  @serializer.serialize
150
172
  assert read_model('post', /body:/).nil?, 'ignore setting'
151
- revert_models
152
173
  end
153
174
 
154
175
  test "serialize as_is setting" do
176
+ revert_models
155
177
  prep_model 'as_is', 'comment'
156
178
  @serializer.serialize
157
179
  assert_equal " postId: DS.attr('integer'),\n", read_model('comment', /postId:/), 'as_is setting'
158
- revert_models
159
180
  end
160
181
 
161
182
  test "serialize finds associations" do
183
+ revert_models
162
184
  File.unlink "#{@mdir}post.js.coffee"
163
185
  @create_serializer.serialize
164
- assert_equal " authorDude: DS.belongsTo('user'),\n", read_model('post', /authorDude:/), 'finds associations'
165
- revert_models
186
+ assert_equal " authorDude: DS.belongsTo('user', {async: true}),\n", read_model('post', /authorDude:/), 'finds associations'
166
187
  end
167
188
 
168
189
  test "skips or creates models" do
190
+ revert_models
169
191
  File.unlink "#{@mdir}post.js.coffee"
170
192
  @serializer.serialize
171
193
  assert !File.exists?("#{@mdir}post.js.coffee"), 'skips model'
172
194
  clear_models
173
195
  @create_serializer.serialize
174
196
  assert_equal 3, Dir["#{@mdir}*js.coffee"].length, 'creates models'
175
- revert_models
176
197
  end
177
198
 
178
199
  test "accepts async argument" do
200
+ revert_models
179
201
  async_args = Rake::TaskArguments.new([],['async:true'])
180
202
  async_serializer = EmberSerialize::Serializer.new(async_args)
181
- # async_serializer.javascripts_dir = @jdir
182
- # async_serializer.models_dir = @mdir
183
203
  prep_model 'async', 'post'
184
204
  async_serializer.serialize
185
205
  lines = read_model('post')
186
- assert lines.grep(/#{async_serializer.eai}/).first.nil?, 'async:true leaves no setting'
206
+ assert lines.grep(/#{async_serializer.eas}/).first.nil?, 'async:true leaves no setting'
187
207
  assert_match /async: true/, lines.grep(/authorDude:/).first, 'accepts async arg'
208
+ end
209
+
210
+ test "parses async argument" do
188
211
  revert_models
212
+ prep_model 'async_parse', 'post'
213
+ @serializer.serialize
214
+ lines = read_model('post')
215
+ assert !lines.grep(/#{@serializer.eas} false/).first.nil?, 'ember_serializer:async false stays'
216
+ assert_no_match /async: true/, lines.grep(/authorDude:/).first, 'parses async arg'
189
217
  end
190
218
 
191
219
  test "accepts engine argument" do
220
+ revert_models
192
221
  # engine serializer
193
222
  engine_args = Rake::TaskArguments.new([],[':create','engine:em'])
194
223
  engine_serializer = EmberSerialize::Serializer.new(engine_args)
@@ -220,6 +249,13 @@ EmberSerialize.Post = DS.Model.extend
220
249
  default_serializer.serialize
221
250
  # serialize should detect coffee and restore missing post
222
251
  assert_equal 3, Dir["#{@mdir}*js.coffee"].length, 'detects coffee engine type'
223
- revert_models
252
+ end
253
+
254
+ test "makes model directory" do
255
+ FileUtils.mv @mdir, "#{@jdir}models_aside"
256
+ some_serializer = EmberSerialize::Serializer.new(@blank_args)
257
+ assert File.exists?(@mdir), "makes model directory"
258
+ FileUtils.rm_r @mdir
259
+ FileUtils.mv "#{@jdir}models_aside", @mdir
224
260
  end
225
261
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  # Configure Rails Environment
2
5
  ENV["RAILS_ENV"] = "test"
3
6
 
@@ -7,8 +10,6 @@ require 'active_model_serializers'
7
10
  require 'rake'
8
11
  require 'fileutils'
9
12
  require 'pry'
10
- require 'coveralls'
11
- Coveralls.wear!
12
13
 
13
14
  Rails.backtrace_cleaner.remove_silencers!
14
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember_serialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Peden
@@ -118,6 +118,7 @@ files:
118
118
  - test/dummy/app/assets/javascripts/models/post.js.coffee
119
119
  - test/dummy/app/assets/javascripts/models/tests/as_is.js.coffee
120
120
  - test/dummy/app/assets/javascripts/models/tests/async.js.coffee
121
+ - test/dummy/app/assets/javascripts/models/tests/async_parse.js.coffee
121
122
  - test/dummy/app/assets/javascripts/models/tests/find_existing.js.coffee
122
123
  - test/dummy/app/assets/javascripts/models/tests/ignore.js.coffee
123
124
  - test/dummy/app/assets/javascripts/models/tests/ignore_outside.js.coffee
@@ -125,9 +126,6 @@ files:
125
126
  - test/dummy/app/assets/stylesheets/application.css
126
127
  - test/dummy/app/assets/stylesheets/scaffold.css
127
128
  - test/dummy/app/controllers/application_controller.rb
128
- - test/dummy/app/controllers/comments_controller.rb
129
- - test/dummy/app/controllers/posts_controller.rb
130
- - test/dummy/app/controllers/users_controller.rb
131
129
  - test/dummy/app/helpers/application_helper.rb
132
130
  - test/dummy/app/models/comment.rb
133
131
  - test/dummy/app/models/post.rb
@@ -209,6 +207,7 @@ test_files:
209
207
  - test/dummy/app/assets/javascripts/models/post.js.coffee
210
208
  - test/dummy/app/assets/javascripts/models/tests/as_is.js.coffee
211
209
  - test/dummy/app/assets/javascripts/models/tests/async.js.coffee
210
+ - test/dummy/app/assets/javascripts/models/tests/async_parse.js.coffee
212
211
  - test/dummy/app/assets/javascripts/models/tests/find_existing.js.coffee
213
212
  - test/dummy/app/assets/javascripts/models/tests/ignore.js.coffee
214
213
  - test/dummy/app/assets/javascripts/models/tests/ignore_outside.js.coffee
@@ -216,9 +215,6 @@ test_files:
216
215
  - test/dummy/app/assets/stylesheets/application.css
217
216
  - test/dummy/app/assets/stylesheets/scaffold.css
218
217
  - test/dummy/app/controllers/application_controller.rb
219
- - test/dummy/app/controllers/comments_controller.rb
220
- - test/dummy/app/controllers/posts_controller.rb
221
- - test/dummy/app/controllers/users_controller.rb
222
218
  - test/dummy/app/helpers/application_helper.rb
223
219
  - test/dummy/app/models/comment.rb
224
220
  - test/dummy/app/models/post.rb
@@ -1,7 +0,0 @@
1
- class CommentsController < ApplicationController
2
- respond_to :json
3
-
4
- def index
5
- respond_with Comment.first(100)
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class PostsController < ApplicationController
2
- respond_to :json
3
-
4
- def index
5
- respond_with Post.first(100)
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class UsersController < ApplicationController
2
- respond_to :json
3
-
4
- def index
5
- respond_with User.first(100)
6
- end
7
- end