montage_rails 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/montage_rails/model_generator.rb +49 -0
  3. data/lib/generators/montage_rails/templates/model.rb +5 -0
  4. data/lib/generators/montage_rails/templates/resource.rb +22 -0
  5. data/lib/generators/montage_rails/templates/test_data.rb +6 -0
  6. data/lib/montage_rails/application_resource.rb +63 -0
  7. data/lib/montage_rails/mock_server.rb +54 -0
  8. data/lib/montage_rails/railtie.rb +5 -0
  9. data/lib/montage_rails/version.rb +1 -1
  10. data/lib/montage_rails.rb +34 -1
  11. data/test/dummy/app/models/movie.rb +1 -0
  12. data/test/dummy/app/models/test_mod.rb +3 -0
  13. data/test/dummy/app/models/test_one.rb +3 -0
  14. data/test/dummy/config/initializers/montage.rb +1 -0
  15. data/test/dummy/config/routes.rb +3 -54
  16. data/test/dummy/log/development.log +8 -0
  17. data/test/dummy/log/test.log +4074 -0
  18. data/test/dummy/test/fixtures/actors.yml +9 -0
  19. data/test/dummy/test/fixtures/movies.yml +17 -0
  20. data/test/dummy/test/fixtures/studios.yml +7 -0
  21. data/test/dummy/test/fixtures/test_mods.yml +9 -0
  22. data/test/dummy/test/fixtures/test_ones.yml +11 -0
  23. data/test/dummy/test/models/actor_test.rb +7 -0
  24. data/test/dummy/test/models/movie_test.rb +7 -0
  25. data/test/dummy/test/models/studio_test.rb +7 -0
  26. data/test/dummy/test/models/test_mod_test.rb +5 -0
  27. data/test/dummy/test/models/test_one_test.rb +7 -0
  28. data/test/dummy/test/montage_resources/actor_resource.rb +26 -0
  29. data/test/dummy/test/montage_resources/movie_resource.rb +43 -0
  30. data/test/dummy/test/montage_resources/studio_resource.rb +18 -0
  31. data/test/dummy/test/montage_resources/test_data/actor_test_data.yml +8 -0
  32. data/test/dummy/test/montage_resources/test_data/movie_test_data.yml +8 -0
  33. data/test/dummy/test/montage_resources/test_data/studio_test_data.yml +3 -0
  34. data/test/dummy/test/resources/test_mod_resource.rb +22 -0
  35. data/test/dummy/test/resources/test_one_resource.rb +26 -0
  36. data/test/dummy/test/test_helper.rb +0 -0
  37. data/test/montage_rails/application_resource_test.rb +92 -0
  38. data/test/montage_rails/base_test.rb +22 -22
  39. data/test/montage_rails/relation_test.rb +1 -1
  40. data/test/montage_rails_test.rb +57 -14
  41. data/test/test_helper.rb +9 -166
  42. metadata +108 -22
  43. data/test/resources/actor_resource.rb +0 -141
  44. data/test/resources/movie_resource.rb +0 -221
  45. data/test/resources/studio_resource.rb +0 -56
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ movie_id: MyText
5
+ name: MyText
6
+
7
+ two:
8
+ movie_id: MyText
9
+ name: MyText
@@ -0,0 +1,17 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ studio_id: MyText
5
+ rank:
6
+ rating:
7
+ title: MyText
8
+ votes:
9
+ year:
10
+
11
+ two:
12
+ studio_id: MyText
13
+ rank:
14
+ rating:
15
+ title: MyText
16
+ votes:
17
+ year:
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: MyText
5
+
6
+ two:
7
+ name: MyText
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ foo: MyText
5
+ bar:
6
+
7
+ two:
8
+ foo: MyText
9
+ bar:
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: MyText
5
+ title: MyText
6
+ age:
7
+
8
+ two:
9
+ name: MyText
10
+ title: MyText
11
+ age:
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ActorTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MovieTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class StudioTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class TestModTest < ActiveSupport::TestCase
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TestOneTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,26 @@
1
+ class ActorResource < MontageRails::ApplicationResource
2
+ def self.schema_definition
3
+ {
4
+ name: "actors",
5
+ fields: [
6
+ {
7
+ name: "movie_id",
8
+ datatype: "text",
9
+ indexed: false,
10
+ required: false
11
+ },
12
+ {
13
+ name: "name",
14
+ datatype: "text",
15
+ indexed: false,
16
+ required: false
17
+ },
18
+ ],
19
+ links: {
20
+ self: "http://testco.dev.montagehot.club/api/v1/schemas/actors/",
21
+ query: "http://testco.dev.montagehot.club/api/v1/schemas/actors/query/",
22
+ create_document: "http://testco.dev.montagehot.club/api/v1/schemas/actors/save/"
23
+ }
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ class MovieResource < MontageRails::ApplicationResource
2
+ def self.schema_definition
3
+ {
4
+ name: "movies",
5
+ fields: [
6
+ {
7
+ name: "studio_id",
8
+ datatype: "text",
9
+ },
10
+ {
11
+ name: "rank",
12
+ datatype: "numeric",
13
+ required: true,
14
+ },
15
+ {
16
+ name: "rating",
17
+ datatype: "numeric",
18
+ required: true,
19
+ },
20
+ {
21
+ name: "title",
22
+ datatype: "text",
23
+ required: true,
24
+ },
25
+ {
26
+ name: "votes",
27
+ datatype: "numeric",
28
+ required: true,
29
+ },
30
+ {
31
+ name: "year",
32
+ datatype: "numeric",
33
+ required: true,
34
+ },
35
+ ],
36
+ links: {
37
+ self: "http://testco.dev.montagehot.club/api/v1/schemas/movies/",
38
+ query: "http://testco.dev.montagehot.club/api/v1/schemas/movies/query/",
39
+ create_document: "http://testco.dev.montagehot.club/api/v1/schemas/movies/save/"
40
+ }
41
+ }
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ class StudioResource < MontageRails::ApplicationResource
2
+ def self.schema_definition
3
+ {
4
+ name: "studios",
5
+ fields: [
6
+ {
7
+ name: "name",
8
+ datatype: "text",
9
+ },
10
+ ],
11
+ links: {
12
+ self: "http://testco.dev.montagehot.club/api/v1/schemas/studios/",
13
+ query: "http://testco.dev.montagehot.club/api/v1/schemas/studios/query/",
14
+ create_document: "http://testco.dev.montagehot.club/api/v1/schemas/studios/save/"
15
+ }
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ -
2
+ movie_id: 69cc93af-1f0e-43bc-ac9a-19117111978e
3
+ name: Steve Martin
4
+ id: fill_me_in
5
+ -
6
+ movie_id: d8332c5b-71a9-423d-8bc8-9d956e7257a4
7
+ name: Mark Hamill
8
+ id: fill_me_in
@@ -0,0 +1,8 @@
1
+ -
2
+ studio_id: 19442e09-5c2d-4e5d-8f34-675570e81414
3
+ rank: 4
4
+ rating: 2.0
5
+ title: The Jerk
6
+ votes: 500
7
+ year: 1983
8
+ id: 69cc93af-1f0e-43bc-ac9a-19117111978e
@@ -0,0 +1,3 @@
1
+ -
2
+ name: Universal
3
+ id: 19442e09-5c2d-4e5d-8f34-675570e81414
@@ -0,0 +1,22 @@
1
+ class TestModResource
2
+ def self.schema_definition
3
+ {
4
+ name: "testmods",
5
+ fields: [
6
+ {
7
+ name: "foo",
8
+ datatype: "text",
9
+ },
10
+ {
11
+ name: "bar",
12
+ datatype: "number",
13
+ },
14
+ ],
15
+ links: {
16
+ self: "http://testco.dev.montagehot.club/api/v1/schemas/testmods/",
17
+ query: "http://testco.dev.montagehot.club/api/v1/schemas/testmods/query/",
18
+ create_document: "http://testco.dev.montagehot.club/api/v1/schemas/testmods/save/"
19
+ }
20
+ }
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ class TestOneResource
2
+ def self.schema_definition
3
+ {
4
+ name: "testones",
5
+ fields: [
6
+ {
7
+ name: "name",
8
+ datatype: "text",
9
+ },
10
+ {
11
+ name: "title",
12
+ datatype: "text",
13
+ },
14
+ {
15
+ name: "age",
16
+ datatype: "number",
17
+ },
18
+ ],
19
+ links: {
20
+ self: "http://testco.dev.montagehot.club/api/v1/schemas/testones/",
21
+ query: "http://testco.dev.montagehot.club/api/v1/schemas/testones/query/",
22
+ create_document: "http://testco.dev.montagehot.club/api/v1/schemas/testones/save/"
23
+ }
24
+ }
25
+ end
26
+ end
File without changes
@@ -0,0 +1,92 @@
1
+ require 'test_helper'
2
+ require 'montage_rails/application_resource'
3
+
4
+ class MontageRails::ApplicationResourceTest < Minitest::Test
5
+
6
+ context 'reading yaml data' do
7
+ setup do
8
+ @resource = MontageRails::ApplicationResource.new
9
+ end
10
+ should 'generate filename from class' do
11
+ expected = File.join(Rails.root, 'test','montage_resources','test_data',
12
+ 'montage_rails','application_test_data.yml')
13
+ assert_equal expected, @resource.class_to_filename
14
+ end
15
+ should 'call class_to_filename when loading YAML' do
16
+ filename='some_string'
17
+ @resource.expects(:class_to_filename).returns(filename)
18
+ YAML.stubs(:load_file)
19
+ @resource.read_yaml
20
+ end
21
+ should 'use class_to_filename when calling YAML' do
22
+ filename='some_string'
23
+ @resource.stubs(:class_to_filename).returns(filename)
24
+ YAML.expects(:load_file).with(filename)
25
+ @resource.read_yaml
26
+ end
27
+ should 'return yaml load data' do
28
+ data = { "some_data"=>"New Data"}
29
+ filename='some_string'
30
+ @resource.stubs(:class_to_filename).returns(filename)
31
+ YAML.stubs(:load_file).with(filename).returns(data)
32
+ assert_equal @resource.read_yaml, data
33
+ end
34
+ end
35
+
36
+ context 'find' do
37
+ setup do
38
+ @resource = MontageRails::ApplicationResource.new
39
+ @resource.expects(:read_yaml).returns([
40
+ {"id"=>1,"name"=>'wrong'},
41
+ {"id"=>2,"name"=>'right'},
42
+ {"id"=>3,"name"=>'extra_wrong'}
43
+ ])
44
+ end
45
+ should 'retrieve an item by id' do
46
+ assert_equal 'right', @resource.find(2)['name']
47
+ end
48
+ end
49
+
50
+ context 'execute_filter' do
51
+ setup do
52
+ @resource = MontageRails::ApplicationResource.new
53
+ end
54
+ should 'parse filter' do
55
+ end
56
+ end
57
+
58
+ context 'execute_filters' do
59
+ setup do
60
+ @resource = MontageRails::ApplicationResource.new
61
+ @item1 = {"name"=>'foo', 'votes'=>1, 'id'=>1}
62
+ @item2 = {"name"=>'bar', 'votes'=>5, 'id'=>2}
63
+ @item3 = {"name"=>'foobar', 'votes'=>10, 'id'=>3}
64
+ @resource.data = [ @item1, @item2, @item3]
65
+ end
66
+ should 'handle equal to relations' do
67
+ @resource.params={'filter'=>{'name'=>'bar'}}
68
+ @resource.execute_filters
69
+ assert_equal [@item2], @resource.data
70
+ end
71
+ should 'handle equal lt relations' do
72
+ @resource.params={'filter'=>{'votes__lt'=>5}}
73
+ @resource.execute_filters
74
+ assert_equal [@item1], @resource.data
75
+ end
76
+ should 'handle equal lte relations' do
77
+ @resource.params={'filter'=>{'votes__lte'=>5}}
78
+ @resource.execute_filters
79
+ assert_equal [@item1,@item2], @resource.data
80
+ end
81
+ should 'handle equal gt relations' do
82
+ @resource.params={'filter'=>{'votes__gt'=>5}}
83
+ @resource.execute_filters
84
+ assert_equal [@item3], @resource.data
85
+ end
86
+ should 'handle equal gte relations' do
87
+ @resource.params={'filter'=>{'votes__gte'=>5}}
88
+ @resource.execute_filters
89
+ assert_equal [@item2,@item3], @resource.data
90
+ end
91
+ end
92
+ end
@@ -26,7 +26,7 @@ class MontageRails::BaseTest < MiniTest::Test
26
26
  end
27
27
 
28
28
  should "initialize with the passed in parameters" do
29
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
29
+ @movie = Movie.new(MovieResource.fetch_item)
30
30
 
31
31
  assert_equal 4, @movie.rank
32
32
  assert_equal 2.0, @movie.rating
@@ -62,7 +62,7 @@ class MontageRails::BaseTest < MiniTest::Test
62
62
 
63
63
  context "callbacks" do
64
64
  should "respond to the before_save callback and before_create callback when it's not persisted" do
65
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
65
+ @movie = Movie.new(MovieResource.fetch_item)
66
66
 
67
67
  @movie.save
68
68
 
@@ -71,7 +71,7 @@ class MontageRails::BaseTest < MiniTest::Test
71
71
  end
72
72
 
73
73
  should "only call the before_create callback if the record is not persisted" do
74
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
74
+ @movie = Movie.create(MovieResource.fetch_item)
75
75
 
76
76
  @movie.before_create_var = nil
77
77
  @movie.before_save_var = nil
@@ -84,7 +84,7 @@ class MontageRails::BaseTest < MiniTest::Test
84
84
  end
85
85
 
86
86
  should "call the before_create callback when created with .save!" do
87
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
87
+ @movie = Movie.new(MovieResource.fetch_item)
88
88
 
89
89
  @movie.save!
90
90
 
@@ -93,13 +93,13 @@ class MontageRails::BaseTest < MiniTest::Test
93
93
  end
94
94
 
95
95
  should "call the before_create callback on creation" do
96
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
96
+ @movie = Movie.create(MovieResource.fetch_item)
97
97
 
98
98
  assert_equal "BAR", @movie.before_create_var
99
99
  end
100
100
 
101
101
  should "respond to the after_save callback and after_create callback when it's not persisted" do
102
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
102
+ @movie = Movie.new(MovieResource.fetch_item)
103
103
 
104
104
  @movie.save
105
105
 
@@ -108,7 +108,7 @@ class MontageRails::BaseTest < MiniTest::Test
108
108
  end
109
109
 
110
110
  should "only call the after_create callback if the record is not persisted" do
111
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
111
+ @movie = Movie.create(MovieResource.fetch_item)
112
112
 
113
113
  @movie.after_create_var = nil
114
114
  @movie.after_save_var = nil
@@ -121,7 +121,7 @@ class MontageRails::BaseTest < MiniTest::Test
121
121
  end
122
122
 
123
123
  should "call the after_create callback on creation" do
124
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
124
+ @movie = Movie.create(MovieResource.fetch_item)
125
125
 
126
126
  assert_equal "AFTER CREATE", @movie.after_create_var
127
127
  end
@@ -136,6 +136,7 @@ class MontageRails::BaseTest < MiniTest::Test
136
136
  end
137
137
 
138
138
  should "create finder methods for all the column names" do
139
+ Movie.respond_to?(:find_by_rank) # fix for the fact that the test will fail if it's the first one run
139
140
  assert Movie.respond_to?(:find_by_rank)
140
141
  assert Movie.respond_to?(:find_by_title)
141
142
  assert Movie.respond_to?(:find_by_votes)
@@ -161,15 +162,14 @@ class MontageRails::BaseTest < MiniTest::Test
161
162
 
162
163
  context ".has_many" do
163
164
  setup do
164
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
165
- @actor = Actor.create(MontageRails::ActorResource.steve_martin)
166
- @actor2 = Actor.create(MontageRails::ActorResource.mark_hamill)
165
+ @movie = Movie.first
166
+ @actor = Actor.where(:name=>'Steve Martin').first
167
+ @actor2 = Actor.where(:name => "Mark Hamill").first
167
168
  end
168
169
 
169
170
  should "define an instance method for the given table name" do
170
171
  assert @movie.respond_to?(:actors)
171
172
 
172
- assert_equal 1, @movie.actors.count
173
173
  assert_equal @actor.attributes, @movie.actors.first.attributes
174
174
  end
175
175
 
@@ -213,7 +213,7 @@ class MontageRails::BaseTest < MiniTest::Test
213
213
  context ".belongs_to" do
214
214
  should "define an instance method for the given table name" do
215
215
  @movie = Movie.find_by_title("The Jerk")
216
- @studio = Studio.create(name: "Universal")
216
+ @studio = Studio.find_by_name("Universal")
217
217
 
218
218
  assert @movie.respond_to?(:studio)
219
219
  assert @movie.respond_to?(:studio=)
@@ -246,7 +246,7 @@ class MontageRails::BaseTest < MiniTest::Test
246
246
 
247
247
  context ".create" do
248
248
  should "save a new object and return an instance of the class" do
249
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
249
+ @movie = Movie.create(MovieResource.fetch_item)
250
250
 
251
251
  assert @movie.persisted?
252
252
  assert_equal 4, @movie.rank
@@ -266,7 +266,7 @@ class MontageRails::BaseTest < MiniTest::Test
266
266
  assert_equal 4, @movie.rank
267
267
  assert_equal 2.0, @movie.rating
268
268
  assert_equal "The Jerk", @movie.title
269
- assert_equal 600, @movie.votes
269
+ assert_equal 500, @movie.votes
270
270
  assert_equal 1983, @movie.year
271
271
  end
272
272
  end
@@ -324,7 +324,7 @@ class MontageRails::BaseTest < MiniTest::Test
324
324
  context "#save" do
325
325
  context "when valid attributes are provided" do
326
326
  setup do
327
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
327
+ @movie = Movie.new(MovieResource.fetch_item)
328
328
  end
329
329
 
330
330
  should "successfully save the document, return a copy of itself, and set persisted to true" do
@@ -347,7 +347,7 @@ class MontageRails::BaseTest < MiniTest::Test
347
347
  end
348
348
 
349
349
  should "not save anything if attributes haven't changed" do
350
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
350
+ @movie = Movie.create(MovieResource.fetch_item)
351
351
 
352
352
  Movie.connection.expects(:create_or_update_documents).never
353
353
 
@@ -357,7 +357,7 @@ class MontageRails::BaseTest < MiniTest::Test
357
357
 
358
358
  context "#update_attributes" do
359
359
  setup do
360
- @movie = Movie.create(MontageRails::MovieResource.to_hash)
360
+ @movie = Movie.create(MovieResource.fetch_item)
361
361
  end
362
362
 
363
363
  context "when valid attributes are given" do
@@ -374,7 +374,7 @@ class MontageRails::BaseTest < MiniTest::Test
374
374
  end
375
375
 
376
376
  should "create a new document" do
377
- @movie.update_attributes(MontageRails::MovieResource.to_hash)
377
+ @movie.update_attributes(MovieResource.fetch_item)
378
378
 
379
379
  assert @movie.persisted?
380
380
  end
@@ -391,7 +391,7 @@ class MontageRails::BaseTest < MiniTest::Test
391
391
  context "when none of the attributes have changed" do
392
392
  should "not update the document" do
393
393
  MontageRails.connection.expects(:update_document).never
394
- @movie.update_attributes(MontageRails::MovieResource.update_body.shift)
394
+ @movie.update_attributes(MovieResource.fetch_item)
395
395
  end
396
396
  end
397
397
 
@@ -419,7 +419,7 @@ class MontageRails::BaseTest < MiniTest::Test
419
419
 
420
420
  context "#dirty?" do
421
421
  should "return true if the model is dirty" do
422
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
422
+ @movie = Movie.new(MovieResource.fetch_item)
423
423
 
424
424
  @movie.title = "FOOOOOBar"
425
425
 
@@ -427,7 +427,7 @@ class MontageRails::BaseTest < MiniTest::Test
427
427
  end
428
428
 
429
429
  should "return false if the model is not dirty" do
430
- @movie = Movie.new(MontageRails::MovieResource.to_hash)
430
+ @movie = Movie.new(MovieResource.fetch_item)
431
431
 
432
432
  refute @movie.dirty?
433
433
  end
@@ -110,7 +110,7 @@ class MontageRails::RelationTest < Minitest::Test
110
110
  end
111
111
 
112
112
  should "query the remote db and return the record set if the records have not already been fetched" do
113
- @movies = MontageRails::Relation.new(Movie).where("votes > 900000").to_a
113
+ @movies = MontageRails::Relation.new(Movie).where("votes > 5").to_a
114
114
 
115
115
  assert_equal 1, @movies.count
116
116
  end
@@ -2,20 +2,6 @@ require 'test_helper'
2
2
 
3
3
  class MontageRailsTest < ActiveSupport::TestCase
4
4
  context ".configure" do
5
- setup do
6
- MontageRails.username = nil
7
- MontageRails.password = nil
8
- MontageRails.token = nil
9
- MontageRails.domain = nil
10
- end
11
-
12
- teardown do
13
- MontageRails.configure do |c|
14
- c.token = "fb761e07-a12b-40bb-a42f-2202ecfd1046"
15
- c.domain = "testco"
16
- end
17
- end
18
-
19
5
  should "accept a username, password, token, and domain" do
20
6
  MontageRails.configure do |c|
21
7
  c.username = "darin"
@@ -35,6 +21,7 @@ class MontageRailsTest < ActiveSupport::TestCase
35
21
  MontageRails.configure do |c|
36
22
  c.username = "darin"
37
23
  c.password = "foo"
24
+ c.domain = nil
38
25
  end
39
26
  end
40
27
  end
@@ -43,6 +30,9 @@ class MontageRailsTest < ActiveSupport::TestCase
43
30
  assert_raises(MontageRails::AttributeMissingError, "You must include a username and password if no token is given") do
44
31
  MontageRails.configure do |c|
45
32
  c.domain = "foo"
33
+ c.username = nil
34
+ c.password = nil
35
+ c.token = nil
46
36
  end
47
37
  end
48
38
  end
@@ -69,6 +59,7 @@ class MontageRailsTest < ActiveSupport::TestCase
69
59
  c.domain = "foo"
70
60
  c.username = "darin"
71
61
  c.password = "foo"
62
+ c.token = nil
72
63
  end
73
64
 
74
65
  assert_equal "foobar", MontageRails.token
@@ -90,8 +81,60 @@ class MontageRailsTest < ActiveSupport::TestCase
90
81
  c.domain = "foo"
91
82
  c.username = "darin"
92
83
  c.password = "bar"
84
+ c.token = nil
93
85
  end
94
86
  end
95
87
  end
88
+
89
+ should 'accept server url' do
90
+ MontageRails.configure do |c|
91
+ c.server_url = 'foobar'
92
+ c.domain = 'foo'
93
+ c.token = 'abc'
94
+ end
95
+ end
96
+
97
+ should 'accept server url even if use mock set to false' do
98
+ MontageRails.configure do |c|
99
+ c.use_mock_server = false
100
+ c.server_url = 'foobar'
101
+ c.domain = 'foo'
102
+ c.token = 'abc'
103
+ end
104
+ MontageRails.debugger = true
105
+ MontageRails.url_prefix
106
+ assert_equal 'foobar', MontageRails.url_prefix, "url_prefix was #{MontageRails.url_prefix} instead of foobar"
107
+ end
108
+
109
+ should 'accept boolean controling mock server use' do
110
+ MontageRails.configure do |c|
111
+ c.use_mock_server = true
112
+ c.domain = 'foo'
113
+ c.token = 'abc'
114
+ end
115
+
116
+ assert_equal MontageRails.use_mock_server, true
117
+ end
118
+
119
+ should 'have nil url_prefix if use mock server set to false' do
120
+ MontageRails.configure do |c|
121
+ c.use_mock_server = false
122
+ c.domain = 'foo'
123
+ c.token = 'abc'
124
+ end
125
+
126
+ assert_equal nil, MontageRails.url_prefix
127
+ end
128
+
129
+ should 'have url_prefix if mock server set to true' do
130
+ MontageRails.configure do |c|
131
+ c.use_mock_server = true
132
+ c.domain = 'foo'
133
+ c.token = 'abc'
134
+ end
135
+
136
+ url_prefix = MontageRails.url_prefix
137
+ assert (url_prefix.include?('localhost') or url_prefix.include? ('http://127.0.0.1:')), 'Url prefix should resolve to localhost, resolved to ' + MontageRails.url_prefix
138
+ end
96
139
  end
97
140
  end