curupira 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curupira might be problematic. Click here for more details.

Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +202 -0
  7. data/README.md +72 -0
  8. data/Rakefile +31 -0
  9. data/app/controllers/curupira/authorized_controller.rb +9 -0
  10. data/app/controllers/curupira/groups_controller.rb +43 -0
  11. data/app/controllers/curupira/passwords_controller.rb +46 -0
  12. data/app/controllers/curupira/roles_controller.rb +43 -0
  13. data/app/controllers/curupira/sessions_controller.rb +30 -0
  14. data/app/controllers/curupira/users_controller.rb +47 -0
  15. data/app/helpers/curupira/authorize_helper.rb +21 -0
  16. data/app/helpers/curupira/relationship_select_options_helper.rb +17 -0
  17. data/app/mailers/curupira/reset_password_mailer.rb +13 -0
  18. data/app/views/curupira/groups/_form.html.erb +28 -0
  19. data/app/views/curupira/groups/_role_group_fields.html.erb +9 -0
  20. data/app/views/curupira/groups/edit.html.erb +3 -0
  21. data/app/views/curupira/groups/index.html.erb +24 -0
  22. data/app/views/curupira/groups/new.html.erb +3 -0
  23. data/app/views/curupira/groups/show.html.erb +32 -0
  24. data/app/views/curupira/passwords/edit.html.erb +14 -0
  25. data/app/views/curupira/passwords/new.html.erb +14 -0
  26. data/app/views/curupira/reset_password_mailer/instructions.html.erb +19 -0
  27. data/app/views/curupira/reset_password_mailer/reseted.html.erb +7 -0
  28. data/app/views/curupira/roles/_authorization_fields.html.erb +10 -0
  29. data/app/views/curupira/roles/_form.html.erb +23 -0
  30. data/app/views/curupira/roles/edit.html.erb +3 -0
  31. data/app/views/curupira/roles/index.html.erb +24 -0
  32. data/app/views/curupira/roles/new.html.erb +3 -0
  33. data/app/views/curupira/roles/show.html.erb +37 -0
  34. data/app/views/curupira/sessions/new.html.erb +17 -0
  35. data/app/views/curupira/shared/_model_links.html.erb +7 -0
  36. data/app/views/curupira/shared/_session_links.html.erb +7 -0
  37. data/app/views/curupira/users/_form.html.erb +43 -0
  38. data/app/views/curupira/users/_group_user_fields.html.erb +20 -0
  39. data/app/views/curupira/users/_role_group_user_fields.html.erb +10 -0
  40. data/app/views/curupira/users/edit.html.erb +3 -0
  41. data/app/views/curupira/users/index.html.erb +28 -0
  42. data/app/views/curupira/users/new.html.erb +3 -0
  43. data/app/views/curupira/users/show.html.erb +28 -0
  44. data/curupira.gemspec +28 -0
  45. data/lib/curupira.rb +16 -0
  46. data/lib/curupira/authorizer.rb +43 -0
  47. data/lib/curupira/rails.rb +30 -0
  48. data/lib/curupira/rails/routes.rb +15 -0
  49. data/lib/curupira/version.rb +3 -0
  50. data/lib/generators/curupira/controllers/controllers_generator.rb +27 -0
  51. data/lib/generators/curupira/install/install_generator.rb +80 -0
  52. data/lib/generators/curupira/install/model_generators_helper.rb +266 -0
  53. data/lib/generators/curupira/routes/routes_generator.rb +21 -0
  54. data/lib/generators/curupira/routes/templates/routes.rb +1 -0
  55. data/lib/generators/curupira/templates/db/migrate/add_curupira_to_users.rb +20 -0
  56. data/lib/generators/curupira/templates/db/migrate/create_action_labels.rb +12 -0
  57. data/lib/generators/curupira/templates/db/migrate/create_authorizations.rb +12 -0
  58. data/lib/generators/curupira/templates/db/migrate/create_features.rb +11 -0
  59. data/lib/generators/curupira/templates/db/migrate/create_group_users.rb +13 -0
  60. data/lib/generators/curupira/templates/db/migrate/create_groups.rb +10 -0
  61. data/lib/generators/curupira/templates/db/migrate/create_role_group_users.rb +12 -0
  62. data/lib/generators/curupira/templates/db/migrate/create_role_groups.rb +13 -0
  63. data/lib/generators/curupira/templates/db/migrate/create_roles.rb +8 -0
  64. data/lib/generators/curupira/templates/db/migrate/sorcery_core.rb +27 -0
  65. data/lib/generators/curupira/templates/models/action_label.rb +2 -0
  66. data/lib/generators/curupira/templates/models/authorization.rb +2 -0
  67. data/lib/generators/curupira/templates/models/feature.rb +2 -0
  68. data/lib/generators/curupira/templates/models/feature_service.rb +4 -0
  69. data/lib/generators/curupira/templates/models/group.rb +2 -0
  70. data/lib/generators/curupira/templates/models/group_user.rb +2 -0
  71. data/lib/generators/curupira/templates/models/role.rb +2 -0
  72. data/lib/generators/curupira/templates/models/role_group.rb +2 -0
  73. data/lib/generators/curupira/templates/models/role_group_user.rb +2 -0
  74. data/lib/generators/curupira/templates/models/service.rb +2 -0
  75. data/lib/generators/curupira/templates/models/user.rb +2 -0
  76. data/lib/generators/curupira/templates/sorcery.rb +462 -0
  77. data/lib/generators/curupira/views/views_generator.rb +27 -0
  78. data/lib/tasks/curupira_tasks.rake +4 -0
  79. data/spec/app_templates/app/models/action_label.rb +2 -0
  80. data/spec/app_templates/app/models/authorization.rb +2 -0
  81. data/spec/app_templates/app/models/feature.rb +2 -0
  82. data/spec/app_templates/app/models/feature_service.rb +2 -0
  83. data/spec/app_templates/app/models/group.rb +4 -0
  84. data/spec/app_templates/app/models/group_user.rb +2 -0
  85. data/spec/app_templates/app/models/role.rb +2 -0
  86. data/spec/app_templates/app/models/role_group.rb +2 -0
  87. data/spec/app_templates/app/models/role_group_user.rb +2 -0
  88. data/spec/app_templates/app/models/service.rb +2 -0
  89. data/spec/app_templates/app/models/user.rb +2 -0
  90. data/spec/app_templates/config/routes.rb +3 -0
  91. data/spec/controllers/controller_spec.rb +40 -0
  92. data/spec/controllers/groups_controller_spec.rb +162 -0
  93. data/spec/controllers/passwords_controller_spec.rb +171 -0
  94. data/spec/controllers/roles_controller_spec.rb +168 -0
  95. data/spec/controllers/sessions_controller_spec.rb +112 -0
  96. data/spec/controllers/users_controller_spec.rb +182 -0
  97. data/spec/curupira/authorization_spec.rb +67 -0
  98. data/spec/dummy/README.rdoc +28 -0
  99. data/spec/dummy/Rakefile +6 -0
  100. data/spec/dummy/app/assets/images/.keep +0 -0
  101. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  102. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  103. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  104. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  105. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  106. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  107. data/spec/dummy/app/mailers/.keep +0 -0
  108. data/spec/dummy/app/models/.keep +0 -0
  109. data/spec/dummy/app/models/action_label.rb +3 -0
  110. data/spec/dummy/app/models/authorization.rb +4 -0
  111. data/spec/dummy/app/models/feature.rb +3 -0
  112. data/spec/dummy/app/models/group.rb +9 -0
  113. data/spec/dummy/app/models/group_user.rb +7 -0
  114. data/spec/dummy/app/models/role.rb +10 -0
  115. data/spec/dummy/app/models/role_group.rb +4 -0
  116. data/spec/dummy/app/models/role_group_user.rb +4 -0
  117. data/spec/dummy/app/models/user.rb +10 -0
  118. data/spec/dummy/app/views/home/index.html.erb +5 -0
  119. data/spec/dummy/app/views/home/test.html.erb +1 -0
  120. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  121. data/spec/dummy/bin/bundle +3 -0
  122. data/spec/dummy/bin/rails +4 -0
  123. data/spec/dummy/bin/rake +4 -0
  124. data/spec/dummy/bin/setup +29 -0
  125. data/spec/dummy/config.ru +4 -0
  126. data/spec/dummy/config/application.rb +25 -0
  127. data/spec/dummy/config/boot.rb +5 -0
  128. data/spec/dummy/config/database.yml +25 -0
  129. data/spec/dummy/config/environment.rb +5 -0
  130. data/spec/dummy/config/environments/development.rb +46 -0
  131. data/spec/dummy/config/environments/production.rb +79 -0
  132. data/spec/dummy/config/environments/test.rb +44 -0
  133. data/spec/dummy/config/initializers/assets.rb +11 -0
  134. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  135. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  136. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/spec/dummy/config/initializers/inflections.rb +16 -0
  138. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  139. data/spec/dummy/config/initializers/session_store.rb +3 -0
  140. data/spec/dummy/config/initializers/sorcery.rb +462 -0
  141. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  142. data/spec/dummy/config/locales/en.yml +23 -0
  143. data/spec/dummy/config/routes.rb +6 -0
  144. data/spec/dummy/config/secrets.yml +22 -0
  145. data/spec/dummy/db/migrate/20150305011941_create_role_group_users.rb +12 -0
  146. data/spec/dummy/db/migrate/20150305011942_create_authorizations.rb +12 -0
  147. data/spec/dummy/db/migrate/20150305011944_create_groups.rb +10 -0
  148. data/spec/dummy/db/migrate/20150305011945_create_roles.rb +8 -0
  149. data/spec/dummy/db/migrate/20150305011946_sorcery_core.rb +27 -0
  150. data/spec/dummy/db/migrate/20150305011947_create_group_users.rb +13 -0
  151. data/spec/dummy/db/migrate/20150305011948_create_role_groups.rb +13 -0
  152. data/spec/dummy/db/migrate/20150312181229_create_action_labels.rb +12 -0
  153. data/spec/dummy/db/migrate/20150312181747_create_features.rb +11 -0
  154. data/spec/dummy/db/schema.rb +112 -0
  155. data/spec/dummy/db/seeds.rb +137 -0
  156. data/spec/dummy/lib/assets/.keep +0 -0
  157. data/spec/dummy/log/.keep +0 -0
  158. data/spec/dummy/public/404.html +67 -0
  159. data/spec/dummy/public/422.html +67 -0
  160. data/spec/dummy/public/500.html +66 -0
  161. data/spec/dummy/public/favicon.ico +0 -0
  162. data/spec/features/link_authorize_spec.rb +25 -0
  163. data/spec/features/list_users_spec.rb +38 -0
  164. data/spec/features/log_in_spec.rb +15 -0
  165. data/spec/generators/curupira/install/action_label_spec.rb +53 -0
  166. data/spec/generators/curupira/install/authorization_generator_spec.rb +51 -0
  167. data/spec/generators/curupira/install/feature_generator_spec.rb +52 -0
  168. data/spec/generators/curupira/install/group_user_generator_spec.rb +51 -0
  169. data/spec/generators/curupira/install/install_generators_spec.rb +159 -0
  170. data/spec/generators/curupira/install/role_generator_spec.rb +38 -0
  171. data/spec/generators/curupira/install/role_group_generator_spec.rb +51 -0
  172. data/spec/generators/curupira/install/role_group_user_generator_spec.rb +52 -0
  173. data/spec/helpers/relationship_select_options_helper_spec.rb +18 -0
  174. data/spec/rails_helper.rb +55 -0
  175. data/spec/spec_helper.rb +87 -0
  176. data/spec/support/factories.rb +64 -0
  177. data/spec/support/generator_spec_helpers.rb +42 -0
  178. data/spec/support/helpers_spec.rb +23 -0
  179. data/spec/support/shared_examples/role_generator_shared_example_spec.rb +13 -0
  180. data/spec/support/sorcery.rb +4 -0
  181. metadata +539 -0
@@ -0,0 +1,51 @@
1
+ require 'rails_helper'
2
+ require 'generators/curupira/install/install_generator'
3
+
4
+ describe Curupira::Generators::InstallGenerator, :generator do
5
+ before do
6
+ provide_existing_routes_file
7
+ end
8
+
9
+ describe "group_user_model" do
10
+ context "no existing group user class" do
11
+ it "generates group user" do
12
+ run_generator
13
+ group_user_class = file("app/models/group_user.rb")
14
+
15
+ expect(group_user_class).to exist
16
+ expect(group_user_class).to have_correct_syntax
17
+ expect(group_user_class).to contain("belongs_to :group")
18
+ expect(group_user_class).to contain("belongs_to :user")
19
+ end
20
+ end
21
+
22
+ context "group user class already exists" do
23
+ it "includes validations" do
24
+ provide_existing_class("group_user")
25
+
26
+ run_generator
27
+ group_user_class = file("app/models/group_user.rb")
28
+
29
+ expect(group_user_class).to exist
30
+ expect(group_user_class).to have_correct_syntax
31
+ expect(group_user_class).to contain("belongs_to :group")
32
+ expect(group_user_class).to contain("belongs_to :user")
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "group user migration" do
38
+ context "group_users table does not exist" do
39
+ it "creates a migration to create the group_users table" do
40
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
41
+
42
+ run_generator
43
+ migration = migration_file("db/migrate/create_group_users.rb")
44
+
45
+ expect(migration).to exist
46
+ expect(migration).to have_correct_syntax
47
+ expect(migration).to contain("create_table :group_users")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,159 @@
1
+ require 'rails_helper'
2
+ require "generators/curupira/install/install_generator"
3
+
4
+ describe Curupira::Generators::InstallGenerator, :generator do
5
+
6
+ before do
7
+ provide_existing_routes_file
8
+ end
9
+
10
+ describe "sorccery initializer" do
11
+ it "is copied to the application" do
12
+ run_generator
13
+ initializer = file("config/initializers/sorcery.rb")
14
+
15
+ expect(initializer).to exist
16
+ expect(initializer).to have_correct_syntax
17
+ expect(initializer).to contain("Rails.application.config.sorcery.configure do |config|")
18
+ end
19
+ end
20
+
21
+ describe "group" do
22
+ context "no existing user group class" do
23
+ it "generates group" do
24
+ run_generator
25
+
26
+ group = file("app/models/group.rb")
27
+
28
+ expect(group).to exist
29
+ expect(group).to contain("validates_presence_of :name")
30
+ expect(group).to contain("has_many :role_groups")
31
+ expect(group).to contain("has_many :roles, through: :role_groups")
32
+ expect(group).to contain("accepts_nested_attributes_for :role_groups, reject_if: :all_blank, allow_destroy: :true")
33
+ expect(group).to contain("scope :active, -> { where active: true }")
34
+ end
35
+ end
36
+
37
+ context "group class already exists" do
38
+ it "includes validations" do
39
+ run_generator
40
+ group = file("app/models/group.rb")
41
+
42
+ expect(group).to exist
43
+ expect(group).to have_correct_syntax
44
+ expect(group).to contain("validates_presence_of :name")
45
+ expect(group).to contain("has_many :role_groups")
46
+ expect(group).to contain("has_many :roles, through: :role_groups")
47
+ expect(group).to contain("accepts_nested_attributes_for :role_groups, reject_if: :all_blank, allow_destroy: :true")
48
+ expect(group).to contain("scope :active, -> { where active: true }")
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "group migration" do
54
+ context "group table does not exist" do
55
+ it "creates a migration to create the group table" do
56
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
57
+
58
+ run_generator
59
+ migration = migration_file("db/migrate/create_groups.rb")
60
+
61
+ expect(migration).to exist
62
+ expect(migration).to have_correct_syntax
63
+ expect(migration).to contain("create_table :groups")
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "user_model" do
69
+ context "no existing user class" do
70
+ it "creates a user class Curupira configurations" do
71
+ run_generator
72
+ user_class = file("app/models/user.rb")
73
+
74
+ expect(user_class).to exist
75
+ expect(user_class).to have_correct_syntax
76
+ expect(user_class).to contain("authenticates_with_sorcery!")
77
+ expect(user_class).to contain("validates_presence_of :email")
78
+ expect(user_class).to contain("has_many :group_users")
79
+ expect(user_class).to contain("has_many :groups, through: :group_users")
80
+ expect(user_class).to contain("has_many :role_group_users, through: :group_users")
81
+ expect(user_class).to contain("accepts_nested_attributes_for :group_users, reject_if: :all_blank, allow_destroy: :true")
82
+ expect(user_class).to contain("scope :all_belonging_to, -> (user) { includes(group_users: :group).where(groups: { id: user.groups }) }")
83
+ end
84
+ end
85
+
86
+ context "user class already exists" do
87
+ it "includes Curupira configurations" do
88
+ provide_existing_user_class
89
+
90
+ run_generator
91
+ user_class = file("app/models/user.rb")
92
+
93
+ expect(user_class).to exist
94
+ expect(user_class).to have_correct_syntax
95
+ expect(user_class).to contain("authenticates_with_sorcery!")
96
+ expect(user_class).to contain("validates_presence_of :email")
97
+ expect(user_class).to contain("has_many :group_users")
98
+ expect(user_class).to contain("has_many :groups, through: :group_users")
99
+ expect(user_class).to contain("has_many :role_group_users, through: :group_users")
100
+ expect(user_class).to contain("accepts_nested_attributes_for :group_users, reject_if: :all_blank, allow_destroy: :true")
101
+ expect(user_class).to contain("scope :all_belonging_to, -> (user) { includes(group_users: :group).where(groups: { id: user.groups }) }")
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "user migration" do
107
+ context "users table does not exist" do
108
+ it "creates a migration to create the users table" do
109
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
110
+
111
+ run_generator
112
+ migration = migration_file("db/migrate/sorcery_core.rb")
113
+
114
+ expect(migration).to exist
115
+ expect(migration).to have_correct_syntax
116
+ expect(migration).to contain("create_table :users")
117
+ end
118
+ end
119
+
120
+ context "existing users table with all curupira columns and indexes" do
121
+ it "does not create a migration" do
122
+ run_generator
123
+ create_migration = migration_file("db/migrate/sorcery_core.rb")
124
+ add_migration = migration_file("db/migrate/add_curupira_to_users.rb")
125
+
126
+ expect(create_migration).not_to exist
127
+ expect(add_migration).not_to exist
128
+ end
129
+ end
130
+
131
+ context "existing users table missing some columns and indexes" do
132
+ it "create a migration to add missing columns and indexes" do
133
+ Struct.new("Named", :name)
134
+ existing_columns = [Struct::Named.new("username")]
135
+ existing_indexes = [Struct::Named.new("index_users_on_username")]
136
+
137
+ allow(ActiveRecord::Base.connection).to receive(:columns).
138
+ with(:users).
139
+ and_return(existing_columns)
140
+
141
+ allow(ActiveRecord::Base.connection).to receive(:indexes).
142
+ with(:users).
143
+ and_return(existing_indexes)
144
+
145
+ run_generator
146
+ migration = migration_file("db/migrate/add_curupira_to_users.rb")
147
+
148
+ expect(migration).to exist
149
+ expect(migration).to have_correct_syntax
150
+ expect(migration).to contain("change_table :users")
151
+ expect(migration).to contain("t.string :email")
152
+ expect(migration).to contain("add_index :users, :reset_password_token")
153
+ expect(migration).not_to contain("t.string :username")
154
+ expect(migration).not_to contain("add_index :users, :index_users_on_username")
155
+ expect(migration).to contain("t.boolean :admin, default: false")
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails_helper'
2
+ require "generators/curupira/install/install_generator"
3
+
4
+ describe Curupira::Generators::InstallGenerator, :generator do
5
+
6
+ before do
7
+ provide_existing_routes_file
8
+ end
9
+
10
+ describe "role_model" do
11
+ context "no existing role class" do
12
+ it_behaves_like "valid role model"
13
+ end
14
+
15
+ context "role class already exists" do
16
+ before do
17
+ provide_existing_class("role")
18
+ end
19
+
20
+ it_behaves_like "valid role model"
21
+ end
22
+ end
23
+
24
+ describe "role migration" do
25
+ context "roles table does not exist" do
26
+ it "creates a migration to create the roles table" do
27
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
28
+
29
+ run_generator
30
+ migration = migration_file("db/migrate/create_roles.rb")
31
+
32
+ expect(migration).to exist
33
+ expect(migration).to have_correct_syntax
34
+ expect(migration).to contain("create_table :roles")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ require 'rails_helper'
2
+ require 'generators/curupira/install/install_generator'
3
+
4
+ describe Curupira::Generators::InstallGenerator, :generator do
5
+ before do
6
+ provide_existing_routes_file
7
+ end
8
+
9
+ describe "role_group_model" do
10
+ context "no existing role group class" do
11
+ it "generates role group" do
12
+ run_generator
13
+ role_group_class = file("app/models/role_group.rb")
14
+
15
+ expect(role_group_class).to exist
16
+ expect(role_group_class).to have_correct_syntax
17
+ expect(role_group_class).to contain("belongs_to :role")
18
+ expect(role_group_class).to contain("belongs_to :group")
19
+ end
20
+ end
21
+
22
+ context "role group class already exists" do
23
+ it "includes validations" do
24
+ provide_existing_class("role_group")
25
+
26
+ run_generator
27
+ role_group_class = file("app/models/role_group.rb")
28
+
29
+ expect(role_group_class).to exist
30
+ expect(role_group_class).to have_correct_syntax
31
+ expect(role_group_class).to contain("belongs_to :group")
32
+ expect(role_group_class).to contain("belongs_to :role")
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "role group migration" do
38
+ context "role_group table does not exist" do
39
+ it "creates a migration to create the role_groups table" do
40
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
41
+
42
+ run_generator
43
+ migration = migration_file("db/migrate/create_role_groups.rb")
44
+
45
+ expect(migration).to exist
46
+ expect(migration).to have_correct_syntax
47
+ expect(migration).to contain("create_table :role_groups")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require 'rails_helper'
2
+ require "generators/curupira/install/install_generator"
3
+
4
+ describe Curupira::Generators::InstallGenerator, :generator do
5
+ before do
6
+ provide_existing_routes_file
7
+ end
8
+
9
+ describe "role_group_user_model" do
10
+ context "no existing role_group_user class" do
11
+ it "generates role_group_user" do
12
+ run_generator
13
+ authorization_class = file("app/models/role_group_user.rb")
14
+
15
+ expect(authorization_class).to exist
16
+ expect(authorization_class).to have_correct_syntax
17
+ expect(authorization_class).to contain("belongs_to :group_user")
18
+ expect(authorization_class).to contain("belongs_to :role")
19
+ end
20
+ end
21
+
22
+ context "role_group_user class already exists" do
23
+ it "includes validations" do
24
+ provide_existing_class("role_group_user")
25
+
26
+ run_generator
27
+ authorization_class = file("app/models/role_group_user.rb")
28
+
29
+ expect(authorization_class).to exist
30
+ expect(authorization_class).to have_correct_syntax
31
+ expect(authorization_class).to contain("belongs_to :group_user")
32
+ expect(authorization_class).to contain("belongs_to :role")
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "role_group_user migration" do
38
+ context "role_group_users table does not exist" do
39
+ it "creates a migration to create the role_group_user table" do
40
+ allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)
41
+
42
+ run_generator
43
+ migration = migration_file("db/migrate/create_role_group_users.rb")
44
+
45
+ expect(migration).to exist
46
+ expect(migration).to have_correct_syntax
47
+ expect(migration).to contain("class CreateRoleGroupUsers < ActiveRecord::Migration")
48
+ expect(migration).to contain("create_table :role_group_users")
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,18 @@
1
+ require "rails_helper"
2
+
3
+ describe Curupira::RelationshipSelectOptionsHelper do
4
+ describe "#active_user_groups_select_options" do
5
+ let!(:active_group1) { FactoryGirl.create(:group, active: true) }
6
+ let!(:active_group2) { FactoryGirl.create(:group, active: true) }
7
+ let!(:inactive_group) { FactoryGirl.create(:group, active: false) }
8
+ let!(:user) { FactoryGirl.create(:user, groups: [active_group1, active_group2]) }
9
+
10
+ it "returns default with active groups" do
11
+ expect(helper.active_user_groups_select_options(user)).to eql [
12
+ ["Selecione um grupo", nil],
13
+ [active_group1.name, active_group1.id],
14
+ [active_group2.name, active_group2.id]
15
+ ]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
5
+ ENV['RAILS_ENV'] ||= 'test'
6
+ require 'spec_helper'
7
+ require File.expand_path('../dummy/config/environment', __FILE__)
8
+ require 'rspec/rails'
9
+ # Add additional requires below this line. Rails is not loaded until this point!
10
+
11
+ # Requires supporting ruby files with custom matchers and macros, etc, in
12
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
13
+ # run as spec files by default. This means that files in spec/support that end
14
+ # in _spec.rb will both be required and run as specs, causing the specs to be
15
+ # run twice. It is recommended that you do not name files matching this glob to
16
+ # end with _spec.rb. You can configure this pattern with the --pattern
17
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
18
+ #
19
+ # The following line is provided for convenience purposes. It has the downside
20
+ # of increasing the boot-up time by auto-requiring all files in the support
21
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
22
+ # require only the support files necessary.
23
+ #
24
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
25
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
26
+
27
+ # Checks for pending migrations before tests are run.
28
+ # If you are not using ActiveRecord, you can remove this line.
29
+ ActiveRecord::Migration.maintain_test_schema!
30
+
31
+ RSpec.configure do |config|
32
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
33
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
34
+
35
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
36
+ # examples within a transaction, remove the following line or assign false
37
+ # instead of true.
38
+ config.use_transactional_fixtures = true
39
+
40
+ # RSpec Rails can automatically mix in different behaviours to your tests
41
+ # based on their file location, for example enabling you to call `get` and
42
+ # `post` in specs under `spec/controllers`.
43
+ #
44
+ # You can disable this behaviour by removing the line below, and instead
45
+ # explicitly tag your specs with their type, e.g.:
46
+ #
47
+ # RSpec.describe UsersController, :type => :controller do
48
+ # # ...
49
+ # end
50
+ #
51
+ # The different available types are documented in the features, such as in
52
+ # https://relishapp.com/rspec/rspec-rails/docs
53
+ config.infer_spec_type_from_file_location!
54
+ config.formatter = :documentation
55
+ end
@@ -0,0 +1,87 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # Many RSpec users commonly either run the entire suite or an individual
61
+ # file, and it's useful to allow more verbose output when running an
62
+ # individual spec file.
63
+ if config.files_to_run.one?
64
+ # Use the documentation formatter for detailed output,
65
+ # unless a formatter has already been configured
66
+ # (e.g. via a command-line flag).
67
+ config.default_formatter = 'doc'
68
+ end
69
+
70
+ # Print the 10 slowest examples and example groups at the
71
+ # end of the spec run, to help surface which specs are running
72
+ # particularly slow.
73
+ config.profile_examples = 10
74
+
75
+ # Run specs in random order to surface order dependencies. If you find an
76
+ # order dependency and want to debug it, you can fix the order by providing
77
+ # the seed, which is printed after each run.
78
+ # --seed 1234
79
+ config.order = :random
80
+
81
+ # Seed global randomization in this process using the `--seed` CLI option.
82
+ # Setting this allows you to use `--seed` to deterministically reproduce
83
+ # test failures related to randomization by passing the same `--seed` value
84
+ # as the one that triggered the failure.
85
+ Kernel.srand config.seed
86
+ =end
87
+ end