conversations 0.0.1

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 (87) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +146 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +55 -0
  7. data/Rakefile +32 -0
  8. data/TODO.md +4 -0
  9. data/app/assets/javascripts/conversations.js +5 -0
  10. data/app/assets/javascripts/jquery.tokeninput.js +860 -0
  11. data/app/assets/stylesheets/conversations.css +4 -0
  12. data/app/assets/stylesheets/token-input-facebook.css +122 -0
  13. data/app/assets/stylesheets/token-input-mac.css +204 -0
  14. data/app/assets/stylesheets/token-input.css +113 -0
  15. data/app/controllers/conversations/conversations_controller.rb +26 -0
  16. data/app/controllers/conversations/messages_controller.rb +17 -0
  17. data/app/controllers/conversations/user_conversations_controller.rb +28 -0
  18. data/app/models/conversations/conversation.rb +19 -0
  19. data/app/models/conversations/message.rb +11 -0
  20. data/app/models/conversations/user_conversation.rb +22 -0
  21. data/app/views/conversations/conversations/new.html.erb +19 -0
  22. data/app/views/conversations/user_conversations/index.html.erb +17 -0
  23. data/app/views/conversations/user_conversations/show.html.erb +35 -0
  24. data/config/routes.rb +12 -0
  25. data/conversations.gemspec +33 -0
  26. data/lib/conversations.rb +19 -0
  27. data/lib/conversations/engine.rb +29 -0
  28. data/lib/conversations/models/conversationalist.rb +22 -0
  29. data/lib/conversations/version.rb +3 -0
  30. data/lib/generators/conversations/conversations_generator.rb +20 -0
  31. data/lib/generators/conversations/templates/20120105153739_create_conversations.rb +9 -0
  32. data/lib/generators/conversations/templates/20120105153800_create_user_conversations.rb +12 -0
  33. data/lib/generators/conversations/templates/20120105153812_create_messages.rb +11 -0
  34. data/lib/tasks/conversations_tasks.rake +4 -0
  35. data/spec/dummy/Rakefile +7 -0
  36. data/spec/dummy/app/assets/javascripts/application.js +10 -0
  37. data/spec/dummy/app/assets/stylesheets/application.css +24 -0
  38. data/spec/dummy/app/controllers/application_controller.rb +13 -0
  39. data/spec/dummy/app/controllers/users_controller.rb +44 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/mailers/.gitkeep +0 -0
  42. data/spec/dummy/app/models/.gitkeep +0 -0
  43. data/spec/dummy/app/models/user.rb +7 -0
  44. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  45. data/spec/dummy/app/views/users/_form.html.erb +5 -0
  46. data/spec/dummy/app/views/users/edit.html.erb +3 -0
  47. data/spec/dummy/app/views/users/index.html.erb +7 -0
  48. data/spec/dummy/app/views/users/new.html.erb +3 -0
  49. data/spec/dummy/app/views/users/show.html.erb +13 -0
  50. data/spec/dummy/config.ru +4 -0
  51. data/spec/dummy/config/application.rb +45 -0
  52. data/spec/dummy/config/boot.rb +10 -0
  53. data/spec/dummy/config/database.yml +25 -0
  54. data/spec/dummy/config/environment.rb +5 -0
  55. data/spec/dummy/config/environments/development.rb +37 -0
  56. data/spec/dummy/config/environments/production.rb +60 -0
  57. data/spec/dummy/config/environments/test.rb +39 -0
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/dummy/config/initializers/inflections.rb +10 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  62. data/spec/dummy/config/initializers/session_store.rb +8 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +5 -0
  65. data/spec/dummy/config/routes.rb +69 -0
  66. data/spec/dummy/db/migrate/20120105152859_create_users.rb +9 -0
  67. data/spec/dummy/db/migrate/20120105153739_create_conversations.rb +9 -0
  68. data/spec/dummy/db/migrate/20120105153800_create_user_conversations.rb +12 -0
  69. data/spec/dummy/db/migrate/20120105153812_create_messages.rb +11 -0
  70. data/spec/dummy/db/schema.rb +45 -0
  71. data/spec/dummy/db/seeds.rb +12 -0
  72. data/spec/dummy/lib/assets/.gitkeep +0 -0
  73. data/spec/dummy/log/.gitkeep +0 -0
  74. data/spec/dummy/public/404.html +26 -0
  75. data/spec/dummy/public/422.html +26 -0
  76. data/spec/dummy/public/500.html +26 -0
  77. data/spec/dummy/public/favicon.ico +0 -0
  78. data/spec/dummy/script/rails +6 -0
  79. data/spec/factories.rb +29 -0
  80. data/spec/integration/conversations_controller_spec.rb +54 -0
  81. data/spec/integration/messages_controller_spec.rb +37 -0
  82. data/spec/integration/user_conversations_controller_spec.rb +51 -0
  83. data/spec/models/conversation_spec.rb +28 -0
  84. data/spec/models/message_spec.rb +23 -0
  85. data/spec/models/user_conversation_spec.rb +18 -0
  86. data/spec/spec_helper.rb +42 -0
  87. metadata +300 -0
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateConversations < ActiveRecord::Migration
2
+ def change
3
+ create_table :conversations do |t|
4
+ t.string :subject
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreateUserConversations < ActiveRecord::Migration
2
+ def change
3
+ create_table :user_conversations do |t|
4
+ t.integer :user_id
5
+ t.integer :conversation_id
6
+ t.boolean :deleted
7
+ t.boolean :read
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMessages < ActiveRecord::Migration
2
+ def change
3
+ create_table :messages do |t|
4
+ t.integer :user_id
5
+ t.integer :conversation_id
6
+ t.text :body
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120105153812) do
15
+
16
+ create_table "conversations", :force => true do |t|
17
+ t.string "subject"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "messages", :force => true do |t|
23
+ t.integer "user_id"
24
+ t.integer "conversation_id"
25
+ t.text "body"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ create_table "user_conversations", :force => true do |t|
31
+ t.integer "user_id"
32
+ t.integer "conversation_id"
33
+ t.boolean "deleted"
34
+ t.boolean "read"
35
+ t.datetime "created_at"
36
+ t.datetime "updated_at"
37
+ end
38
+
39
+ create_table "users", :force => true do |t|
40
+ t.string "name"
41
+ t.datetime "created_at"
42
+ t.datetime "updated_at"
43
+ end
44
+
45
+ end
@@ -0,0 +1,12 @@
1
+ User.delete_all
2
+ user1 = User.create!(:name => 'Max Mustermann')
3
+ user2 = User.create!(:name => 'John Doe')
4
+ user3 = User.create!(:name => 'Juan Lopez')
5
+
6
+ Conversations::UserConversation.delete_all
7
+ Conversations::Conversation.delete_all
8
+ Conversations::Message.delete_all
9
+
10
+ # uc1 = Conversations::UserConversation.new :user_id => user1.id, :to_tokens => "#{user2.id},#{user3.id}"
11
+ # uc1.conversation :subject => 'Test'
12
+ # uc1.save!
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,29 @@
1
+ # This will guess the User class
2
+ FactoryGirl.define do
3
+ sequence :name do |n|
4
+ "John Doe#{n}"
5
+ end
6
+
7
+ factory :user do
8
+ name { FactoryGirl.generate(:name) }
9
+ end
10
+
11
+ sequence :subject do |n|
12
+ "Subject#{n}"
13
+ end
14
+
15
+ factory :conversation, :class => 'conversations/conversation' do
16
+ subject { FactoryGirl.generate(:subject) }
17
+ end
18
+
19
+ factory :message, :class => 'conversations/message' do
20
+ association :user
21
+ association :conversation
22
+ body "Test"
23
+ end
24
+
25
+ factory :user_conversation, :class => 'conversations/user_conversation' do
26
+ association :user
27
+ association :conversation
28
+ end
29
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conversations do
4
+ include Capybara::DSL
5
+
6
+ it "should be valid" do
7
+ Conversations.should be_a(Module)
8
+ end
9
+
10
+ it "should be a valid app" do
11
+ ::Rails.application.should be_a(Dummy::Application)
12
+ end
13
+ end
14
+
15
+ feature "Conversation", %q{} do
16
+
17
+ background do
18
+ @sender = FactoryGirl.create(:user)
19
+ @recipient = FactoryGirl.create(:user)
20
+ @user_conversation = FactoryGirl.create(:user_conversation, :user => @recipient)
21
+ @user_conversation.conversation.users << @recipient
22
+ @user_conversation.conversation.users << @sender
23
+ @user_conversation.conversation.save!
24
+ end
25
+
26
+ scenario "create a new conversation" do
27
+ visit user_path @sender
28
+ click_link 'Sign In as This User'
29
+
30
+ params = {"conversations_conversation"=>{"to_tokens"=>"#{@recipient.id}",
31
+ "subject"=>"Test Conversation",
32
+ "messages_attributes"=>{"0"=>{"body"=>"Test"}}},
33
+ "commit"=>"Create Conversation",
34
+ "user_id"=>"#{@sender.id}"}
35
+
36
+ post user_conversations_path params
37
+ response.should redirect_to user_conversation_path(@sender, @sender.user_conversations.last)
38
+ flash[:notice].should_not be_nil
39
+ end
40
+
41
+ scenario "return to from committing a invalid conversation" do
42
+ visit user_path @sender
43
+ click_link 'Sign In as This User'
44
+
45
+ params = {"conversations_conversation"=>{"to_tokens"=>"#{@recipient.id}",
46
+ "messages_attributes"=>{"0"=>{"body"=>"Test"}}},
47
+ "commit"=>"Create Conversation",
48
+ "user_id"=>"#{@sender.id}"}
49
+
50
+ post user_conversations_path params
51
+ response.should render_template("new")
52
+ end
53
+
54
+ end
@@ -0,0 +1,37 @@
1
+ feature "Message", %q{} do
2
+
3
+ background do
4
+ @sender = FactoryGirl.create(:user)
5
+ @recipient = FactoryGirl.create(:user)
6
+ @user_conversation = FactoryGirl.create(:user_conversation, :user => @recipient)
7
+ @user_conversation.conversation.users << @recipient
8
+ @user_conversation.conversation.users << @sender
9
+ @user_conversation.conversation.save!
10
+ end
11
+
12
+ scenario "create a new conversation" do
13
+ visit user_path @sender
14
+ click_link 'Sign In as This User'
15
+
16
+ params = {"conversations_message"=>{"body"=>"Test"},
17
+ "commit"=>"Create Message",
18
+ "user_id"=>@sender.id,
19
+ "conversation_id"=>@user_conversation.conversation.id}
20
+
21
+ post user_conversation_messages_path params
22
+ response.should redirect_to user_conversation_path(@sender, @user_conversation.conversation)
23
+ end
24
+
25
+ scenario "return to from committing a invalid conversation" do
26
+ visit user_path @sender
27
+ click_link 'Sign In as This User'
28
+
29
+ params = {"commit"=>"Create Message",
30
+ "user_id"=>@sender.id,
31
+ "conversation_id"=>@user_conversation.conversation.id}
32
+
33
+ post user_conversation_messages_path params
34
+ response.should render_template("show")
35
+ end
36
+
37
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ feature "UserConversation", %q{} do
4
+
5
+ background do
6
+ @sender = FactoryGirl.create(:user)
7
+ @recipient = FactoryGirl.create(:user)
8
+ @user_conversation = FactoryGirl.create(:user_conversation, :user => @recipient)
9
+ @user_conversation.conversation.users << @recipient
10
+ @user_conversation.conversation.users << @sender
11
+ @user_conversation.conversation.save!
12
+
13
+ visit user_path @sender
14
+ click_link 'Sign In as This User'
15
+
16
+ params = {"conversations_conversation"=>{"to_tokens"=>"#{@recipient.id}",
17
+ "subject"=>"Test Conversation",
18
+ "messages_attributes"=>{"0"=>{"body"=>"Test"}}},
19
+ "commit"=>"Create Conversation",
20
+ "user_id"=>"#{@sender.id}"}
21
+
22
+ post user_conversations_path params
23
+ end
24
+
25
+ scenario "view a list of conversations" do
26
+ visit user_conversations_path @sender
27
+ page.should have_content('Test Conversation')
28
+ end
29
+
30
+ scenario "view new conversation form" do
31
+ visit new_user_conversation_path @sender
32
+ page.should have_content('To tokens')
33
+ end
34
+
35
+ scenario "view a conversation" do
36
+ visit user_conversation_path @sender, @user_conversation
37
+ page.should have_content('From')
38
+ end
39
+
40
+ scenario "mark a conversation as un/read" do
41
+ visit user_path @recipient
42
+ click_link 'Sign In as This User'
43
+ visit user_conversation_path @recipient, @user_conversation
44
+ page.should have_content('Mark as read')
45
+ click_link 'Mark as read'
46
+ page.should have_content('Mark as unread')
47
+ click_link 'Mark as unread'
48
+ page.should have_content('Mark as read')
49
+ end
50
+
51
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conversations::Conversation do
4
+ let(:conversation) { Factory(:conversation) }
5
+
6
+ before { @user = Factory.create(:user) }
7
+
8
+ context "when subject given" do
9
+ it { conversation.should be_valid }
10
+ end
11
+
12
+ context "when subject empty" do
13
+ before { conversation.subject = nil }
14
+ it { conversation.should_not be_valid }
15
+ end
16
+
17
+ context "when tokens_to are given" do
18
+ before {conversation.users << @user }
19
+ it { conversation.user_ids.should include(@user.id) }
20
+ end
21
+
22
+ context "when user_ids are empty" do
23
+ before { conversation.user_ids = nil }
24
+ it { conversation.user_ids.should_not include(@user.id) }
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conversations::Message do
4
+ let(:message) { Factory(:message) }
5
+
6
+ before { @user = Factory.create(:user) }
7
+
8
+ context "when body given" do
9
+ it { message.should be_valid }
10
+ end
11
+
12
+ context "when body empty" do
13
+ before { message.body = nil }
14
+ it { message.should_not be_valid }
15
+ end
16
+
17
+ context "when user empty" do
18
+ before { message.user = nil }
19
+ it { message.should_not be_valid }
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conversations::UserConversation do
4
+ let(:user_conversation) { Factory(:user_conversation) }
5
+
6
+ before { @user = Factory.create(:user) }
7
+
8
+ context "when subject given" do
9
+ it { user_conversation.should be_valid }
10
+ end
11
+
12
+ context "when user empty" do
13
+ before { user_conversation.user = nil }
14
+ it { user_conversation.should_not be_valid }
15
+ end
16
+
17
+ end
18
+