simple_token_authentication 1.0.0.beta.5

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.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +674 -0
  3. data/README.md +134 -0
  4. data/Rakefile +32 -0
  5. data/lib/simple_token_authentication.rb +5 -0
  6. data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +33 -0
  7. data/lib/simple_token_authentication/acts_as_token_authentication_handler.rb +68 -0
  8. data/lib/simple_token_authentication/version.rb +3 -0
  9. data/lib/tasks/simple_token_authentication_tasks.rake +4 -0
  10. data/test/dummy/README.rdoc +28 -0
  11. data/test/dummy/Rakefile +6 -0
  12. data/test/dummy/app/assets/javascripts/application.js +13 -0
  13. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  14. data/test/dummy/app/assets/javascripts/private_posts.js +2 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  17. data/test/dummy/app/assets/stylesheets/private_posts.css +4 -0
  18. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  19. data/test/dummy/app/controllers/application_controller.rb +21 -0
  20. data/test/dummy/app/controllers/posts_controller.rb +62 -0
  21. data/test/dummy/app/controllers/private_posts_controller.rb +63 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  24. data/test/dummy/app/helpers/private_posts_helper.rb +2 -0
  25. data/test/dummy/app/models/post.rb +3 -0
  26. data/test/dummy/app/models/private_post.rb +3 -0
  27. data/test/dummy/app/models/user.rb +2 -0
  28. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  29. data/test/dummy/app/views/posts/_form.html.erb +29 -0
  30. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  31. data/test/dummy/app/views/posts/index.html.erb +31 -0
  32. data/test/dummy/app/views/posts/new.html.erb +5 -0
  33. data/test/dummy/app/views/posts/show.html.erb +19 -0
  34. data/test/dummy/app/views/private_posts/_form.html.erb +29 -0
  35. data/test/dummy/app/views/private_posts/edit.html.erb +6 -0
  36. data/test/dummy/app/views/private_posts/index.html.erb +31 -0
  37. data/test/dummy/app/views/private_posts/new.html.erb +5 -0
  38. data/test/dummy/app/views/private_posts/show.html.erb +19 -0
  39. data/test/dummy/bin/bundle +3 -0
  40. data/test/dummy/bin/rails +4 -0
  41. data/test/dummy/bin/rake +4 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/config/application.rb +23 -0
  44. data/test/dummy/config/boot.rb +5 -0
  45. data/test/dummy/config/database.yml +25 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +29 -0
  48. data/test/dummy/config/environments/production.rb +80 -0
  49. data/test/dummy/config/environments/test.rb +36 -0
  50. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test/dummy/config/initializers/indefinite_articlerize.rb +4 -0
  53. data/test/dummy/config/initializers/inflections.rb +16 -0
  54. data/test/dummy/config/initializers/mime_types.rb +5 -0
  55. data/test/dummy/config/initializers/secret_token.rb +12 -0
  56. data/test/dummy/config/initializers/session_store.rb +3 -0
  57. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/test/dummy/config/locales/en.yml +23 -0
  59. data/test/dummy/config/routes.rb +60 -0
  60. data/test/dummy/db/development.sqlite3 +0 -0
  61. data/test/dummy/db/migrate/20140107041016_create_posts.rb +11 -0
  62. data/test/dummy/db/migrate/20140107053025_create_users.rb +6 -0
  63. data/test/dummy/db/migrate/20140107064508_create_private_posts.rb +11 -0
  64. data/test/dummy/db/schema.rb +35 -0
  65. data/test/dummy/db/test.sqlite3 +0 -0
  66. data/test/dummy/lib/generators/rspec/controller/controller_generator.rb +33 -0
  67. data/test/dummy/lib/generators/rspec/helper/helper_generator.rb +15 -0
  68. data/test/dummy/lib/generators/rspec/model/model_generator.rb +22 -0
  69. data/test/dummy/lib/generators/rspec/scaffold/scaffold_generator.rb +192 -0
  70. data/test/dummy/lib/templates/rspec/controller/controller_spec.rb +16 -0
  71. data/test/dummy/lib/templates/rspec/controller/view_spec.rb +5 -0
  72. data/test/dummy/lib/templates/rspec/helper/helper_spec.rb +0 -0
  73. data/test/dummy/lib/templates/rspec/model/model_spec.rb +65 -0
  74. data/test/dummy/lib/templates/rspec/model/model_spec_backup.rb +19 -0
  75. data/test/dummy/lib/templates/rspec/scaffold/controller_spec.rb +168 -0
  76. data/test/dummy/lib/templates/rspec/scaffold/edit_spec.rb +31 -0
  77. data/test/dummy/lib/templates/rspec/scaffold/index_spec.rb +32 -0
  78. data/test/dummy/lib/templates/rspec/scaffold/new_spec.rb +30 -0
  79. data/test/dummy/lib/templates/rspec/scaffold/routing_spec.rb +39 -0
  80. data/test/dummy/lib/templates/rspec/scaffold/show_spec.rb +28 -0
  81. data/test/dummy/log/development.log +3437 -0
  82. data/test/dummy/log/test.log +22013 -0
  83. data/test/dummy/public/404.html +58 -0
  84. data/test/dummy/public/422.html +58 -0
  85. data/test/dummy/public/500.html +57 -0
  86. data/test/dummy/public/favicon.ico +0 -0
  87. data/test/dummy/spec/controllers/posts_controller_spec.rb +161 -0
  88. data/test/dummy/spec/controllers/private_posts_controller_spec.rb +41 -0
  89. data/test/dummy/spec/factories/posts.rb +11 -0
  90. data/test/dummy/spec/factories/private_posts.rb +11 -0
  91. data/test/dummy/spec/helpers/posts_helper_spec.rb +0 -0
  92. data/test/dummy/spec/helpers/private_posts_helper_spec.rb +0 -0
  93. data/test/dummy/spec/models/post_spec.rb +65 -0
  94. data/test/dummy/spec/models/private_post_spec.rb +65 -0
  95. data/test/dummy/spec/models/user_spec.rb +61 -0
  96. data/test/dummy/spec/requests/posts_spec.rb +16 -0
  97. data/test/dummy/spec/requests/private_posts_spec.rb +17 -0
  98. data/test/dummy/spec/routing/posts_routing_spec.rb +35 -0
  99. data/test/dummy/spec/routing/private_posts_routing_spec.rb +35 -0
  100. data/test/dummy/spec/spec_helper.rb +42 -0
  101. data/test/dummy/spec/support/factory_girl.rb +6 -0
  102. data/test/dummy/spec/views/posts/edit.html.erb_spec.rb +22 -0
  103. data/test/dummy/spec/views/posts/index.html.erb_spec.rb +26 -0
  104. data/test/dummy/spec/views/posts/new.html.erb_spec.rb +22 -0
  105. data/test/dummy/spec/views/posts/show.html.erb_spec.rb +19 -0
  106. data/test/dummy/spec/views/private_posts/edit.html.erb_spec.rb +22 -0
  107. data/test/dummy/spec/views/private_posts/index.html.erb_spec.rb +26 -0
  108. data/test/dummy/spec/views/private_posts/new.html.erb_spec.rb +22 -0
  109. data/test/dummy/spec/views/private_posts/show.html.erb_spec.rb +19 -0
  110. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  111. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  112. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  113. data/test/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  114. data/test/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
  115. data/test/dummy/tmp/cache/assets/test/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
  116. data/test/dummy/tmp/cache/assets/test/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
  117. data/test/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
  118. data/test/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  119. data/test/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
  120. data/test/dummy/tmp/cache/assets/test/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
  121. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  122. data/test/dummy/tmp/cache/assets/test/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
  123. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  124. data/test/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
  125. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  126. data/test/simple_token_authentication_test.rb +7 -0
  127. data/test/test_helper.rb +15 -0
  128. metadata +384 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ describe PostsController do
22
+
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # Post. As you add validations to Post, be sure to
25
+ # adjust the attributes here as well.
26
+ let(:valid_attributes) { FactoryGirl.attributes_for(:post) }
27
+ let(:invalid_attributes) { FactoryGirl.attributes_for(:invalid_post) }
28
+
29
+ # This should return the minimal set of values that should be in the session
30
+ # in order to pass any filters (e.g. authentication) defined in
31
+ # PostsController. Be sure to keep this updated too.
32
+ let(:valid_session) { {} }
33
+
34
+ describe "GET index" do
35
+ it "assigns all posts as @posts" do
36
+ post = Post.create! valid_attributes
37
+ get :index, {}, valid_session
38
+ assigns(:posts).should eq([post])
39
+ end
40
+ end
41
+
42
+ describe "GET show" do
43
+ it "assigns the requested post as @post" do
44
+ post = Post.create! valid_attributes
45
+ get :show, {:id => post.to_param}, valid_session
46
+ assigns(:post).should eq(post)
47
+ end
48
+ end
49
+
50
+ describe "GET new" do
51
+ it "assigns a new post as @post" do
52
+ get :new, {}, valid_session
53
+ assigns(:post).should be_a_new(Post)
54
+ end
55
+ end
56
+
57
+ describe "GET edit" do
58
+ it "assigns the requested post as @post" do
59
+ post = Post.create! valid_attributes
60
+ get :edit, {:id => post.to_param}, valid_session
61
+ assigns(:post).should eq(post)
62
+ end
63
+ end
64
+
65
+ describe "POST create" do
66
+ describe "with valid params" do
67
+ it "creates a new Post" do
68
+ expect {
69
+ post :create, {:post => valid_attributes}, valid_session
70
+ }.to change(Post, :count).by(1)
71
+ end
72
+
73
+ it "assigns a newly created post as @post" do
74
+ post :create, {:post => valid_attributes}, valid_session
75
+ assigns(:post).should be_a(Post)
76
+ assigns(:post).should be_persisted
77
+ end
78
+
79
+ it "redirects to the created post" do
80
+ post :create, {:post => valid_attributes}, valid_session
81
+ response.should redirect_to(Post.last)
82
+ end
83
+ end
84
+
85
+ describe "with invalid params" do
86
+ it "assigns a newly created but unsaved post as @post" do
87
+ # Trigger the behavior that occurs when invalid params are submitted
88
+ Post.any_instance.stub(:save).and_return(false)
89
+ post :create, {:post => invalid_attributes}, valid_session
90
+ assigns(:post).should be_a_new(Post)
91
+ end
92
+
93
+ it "re-renders the 'new' template" do
94
+ # Trigger the behavior that occurs when invalid params are submitted
95
+ Post.any_instance.stub(:save).and_return(false)
96
+ post :create, {:post => invalid_attributes}, valid_session
97
+ response.should render_template("new")
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "PUT update" do
103
+ describe "with valid params" do
104
+ it "updates the requested post" do
105
+ post = Post.create! valid_attributes
106
+ # Assuming there are no other posts in the database, this
107
+ # specifies that the Post created on the previous line
108
+ # receives the :update_attributes message with whatever params are
109
+ # submitted in the request.
110
+ Post.any_instance.should_receive(:update).with({ "title" => "MyString" })
111
+ put :update, {:id => post.to_param, :post => { "title" => "MyString" }}, valid_session
112
+ end
113
+
114
+ it "assigns the requested post as @post" do
115
+ post = Post.create! valid_attributes
116
+ put :update, {:id => post.to_param, :post => valid_attributes}, valid_session
117
+ assigns(:post).should eq(post)
118
+ end
119
+
120
+ it "redirects to the post" do
121
+ post = Post.create! valid_attributes
122
+ put :update, {:id => post.to_param, :post => valid_attributes}, valid_session
123
+ response.should redirect_to(post)
124
+ end
125
+ end
126
+
127
+ describe "with invalid params" do
128
+ it "assigns the post as @post" do
129
+ post = Post.create! valid_attributes
130
+ # Trigger the behavior that occurs when invalid params are submitted
131
+ Post.any_instance.stub(:save).and_return(false)
132
+ put :update, {:id => post.to_param, :post => invalid_attributes}, valid_session
133
+ assigns(:post).should eq(post)
134
+ end
135
+
136
+ it "re-renders the 'edit' template" do
137
+ post = Post.create! valid_attributes
138
+ # Trigger the behavior that occurs when invalid params are submitted
139
+ Post.any_instance.stub(:save).and_return(false)
140
+ put :update, {:id => post.to_param, :post => invalid_attributes}, valid_session
141
+ response.should render_template("edit")
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "DELETE destroy" do
147
+ it "destroys the requested post" do
148
+ post = Post.create! valid_attributes
149
+ expect {
150
+ delete :destroy, {:id => post.to_param}, valid_session
151
+ }.to change(Post, :count).by(-1)
152
+ end
153
+
154
+ it "redirects to the posts list" do
155
+ post = Post.create! valid_attributes
156
+ delete :destroy, {:id => post.to_param}, valid_session
157
+ response.should redirect_to(posts_url)
158
+ end
159
+ end
160
+
161
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ describe PrivatePostsController do
22
+
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # PrivatePost. As you add validations to PrivatePost, be sure to
25
+ # adjust the attributes here as well.
26
+ let(:valid_attributes) { FactoryGirl.attributes_for(:private_post) }
27
+ let(:invalid_attributes) { FactoryGirl.attributes_for(:invalid_private_post) }
28
+
29
+ # This should return the minimal set of values that should be in the session
30
+ # in order to pass any filters (e.g. authentication) defined in
31
+ # PrivatePostsController. Be sure to keep this updated too.
32
+ let(:valid_session) { {} }
33
+
34
+ describe "actions" do
35
+ it "all require authentication" do
36
+ # That's true for all actions, yet I think there's no need to repeat them all here.
37
+ lambda { get :index, {}, valid_session }.should raise_exception(RuntimeError)
38
+ lambda { get :new, {}, valid_session }.should raise_exception(RuntimeError)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :post do
5
+ title "Gems testing with RSpec and Cucumber"
6
+ end
7
+
8
+ factory :invalid_post, class: :post do
9
+ body "TODO"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :private_post do
5
+ title "Secret spaghetti recipe"
6
+ end
7
+
8
+ factory :invalid_private_post, class: :private_post do
9
+ body "TODO"
10
+ end
11
+ end
File without changes
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Post do
4
+
5
+ # attributes
6
+
7
+ it "has a title" do
8
+ should respond_to :title
9
+ end
10
+
11
+ it "has a body" do
12
+ should respond_to :body
13
+ end
14
+
15
+ it "has a state" do
16
+ should respond_to :published
17
+ end
18
+
19
+ # associations
20
+
21
+ # Uncomment if your model has associations.
22
+ # See https://github.com/thoughtbot/shoulda
23
+ #
24
+ # it "belongs to a 'model'" do
25
+ # should belong_to :model
26
+ # end
27
+
28
+ # validations
29
+
30
+ # See https://github.com/thoughtbot/factory_girl
31
+ # This factory should only set the REQUIRED attributes.
32
+ it "has a valid factory" do
33
+ FactoryGirl.build(:post).should be_valid
34
+ end
35
+ #
36
+ # Uncomment if your model has required attributes.
37
+ # This factory should set no attributes and is useful when invalid
38
+ # attributes or objects are required.
39
+ # See FactoryGirl.attributes_for() documentation
40
+ #
41
+ it "has an invalid factory" do
42
+ FactoryGirl.build(:invalid_post).should_not be_valid
43
+ end
44
+
45
+ # Uncomment if your model has required attributes
46
+ #
47
+ # This is the BDD way of testing attributes presence validation
48
+ # See https://www.relishapp.com/rspec/rspec-rails/docs/model-specs/errors-on
49
+ #
50
+ # it "fails validation with no 'attribute'" do
51
+ # expect(Post.new).to have(1).error_on(:attribute)
52
+ # end
53
+ #
54
+ # And this is an alternative way, which takes advantage of factories,
55
+ # it's up to you to chose one, the other, or use both together.
56
+ #
57
+ it "requires a 'title'" do
58
+ FactoryGirl.build(:post, title: "").should_not be_valid
59
+ end
60
+
61
+ # methods
62
+
63
+ # Describe here you model methods behaviour.
64
+
65
+ end