9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/generators/kitestrings/messages_generator.rb', line 9
def setup_messages_model
template "message.rb.erb", "app/models/message.rb"
copy_file "message_mailer.rb", "app/mailers/message_mailer.rb"
copy_file "default.text.erb", "app/views/message_mailer/default.text.erb"
copy_file "message_spec.rb", "spec/models/message_spec.rb"
copy_file "messages.rb", "spec/factories/messages.rb"
copy_file "messages_controller.rb", "app/controllers/messages_controller.rb"
copy_file "messages_controller_spec.rb", "spec/controllers/messages_controller_spec.rb"
copy_file "index.html.haml", "app/views/messages/index.html.haml"
copy_file "show.html.haml", "app/views/messages/show.html.haml"
if Dir.glob(destination_root + "/db/migrate/*create_messages.rb").count == 0
migration_template "message_migration.rb", "db/migrate/create_messages.rb"
end
routes = " resources :messages, only: [:index, :show]\n # also nest under user, for example:\n # resources :user do\n # resources :messages, only: [:index, :show]\n # end\n"
inject_into_file "config/routes.rb", routes, :before => /^end/
puts "-------------------------------------------------------------------------------\n\nKitestrings Message scaffold. Please complete the following manually:\n\n1. Check config/routes.rb for nesting messages under the user model. For example:\n\n resources :user do\n resources :messages, only: [:index, :show]\n end\n\n2. Update CanCan abilities so users can read their messages, for example:\n\n can(:read, Message) { |message| message.user == user }\n can(:index_all, Message) if user.admin?\n\n3. Add the following to your user model\n\n has_many :messages\n\n4. Set the default host. This is needed as the Message model needs to generate\n absolute URLs to be inserted into email bodies. Example, add to routes.rb:\n\n default_url_options :host => (ENV['DEFAULT_URL_HOST'] || 'localhost')\n\n5. Add \"message\" and \"message_other\" to your common lets. Example:\n\n # Messages\n let(:message) { create :message, user: user }\n let(:message_other) { create :message, user: user_other }\n\n-------------------------------------------------------------------------------\n"
end
|