addressbook 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +21 -0
- data/app/assets/images/addressbook/default.png +0 -0
- data/app/assets/javascripts/addressbook/application.js +15 -0
- data/app/assets/stylesheets/addressbook/application.css +15 -0
- data/app/controllers/addressbook/application_controller.rb +11 -0
- data/app/controllers/addressbook/contacts_controller.rb +96 -0
- data/app/controllers/addressbook/groups_controller.rb +53 -0
- data/app/helpers/addressbook/application_helper.rb +25 -0
- data/app/models/concerns/addressbook_owner.rb +29 -0
- data/app/views/addressbook/contacts/_address.html.erb +35 -0
- data/app/views/addressbook/contacts/_email.html.erb +15 -0
- data/app/views/addressbook/contacts/_form.html.erb +97 -0
- data/app/views/addressbook/contacts/_phone.html.erb +19 -0
- data/app/views/addressbook/contacts/destroy.js.erb +1 -0
- data/app/views/addressbook/contacts/edit.html.erb +3 -0
- data/app/views/addressbook/contacts/index.html.erb +115 -0
- data/app/views/addressbook/contacts/new.html.erb +3 -0
- data/app/views/addressbook/groups/_form.html.erb +25 -0
- data/app/views/addressbook/groups/destroy.js.erb +1 -0
- data/app/views/addressbook/groups/edit.html.erb +3 -0
- data/app/views/addressbook/groups/index.html.erb +29 -0
- data/app/views/addressbook/groups/new.html.erb +3 -0
- data/app/views/layouts/addressbook/application.html.erb +24 -0
- data/config/initializers/addressbook.rb +1 -0
- data/config/locales/en.yml +73 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20141110080715_add_addressbook_account_id_to_user_table.rb +11 -0
- data/lib/addressbook.rb +23 -0
- data/lib/addressbook/account.rb +27 -0
- data/lib/addressbook/base_uploader.rb +33 -0
- data/lib/addressbook/contact.rb +128 -0
- data/lib/addressbook/engine.rb +10 -0
- data/lib/addressbook/group.rb +18 -0
- data/lib/addressbook/import_file_uploader.rb +7 -0
- data/lib/addressbook/photo_uploader.rb +27 -0
- data/lib/addressbook/resource.rb +24 -0
- data/lib/addressbook/version.rb +3 -0
- data/lib/generators/addressbook/controllers/controllers_generator.rb +42 -0
- data/lib/generators/addressbook/initializer/initializer_generator.rb +9 -0
- data/lib/generators/addressbook/views/views_generator.rb +42 -0
- data/lib/tasks/addressbook_tasks.rake +4 -0
- data/spec/controllers/addressbook/contacts_controller_spec.rb +169 -0
- data/spec/controllers/addressbook/groups_controller_spec.rb +106 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/account.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/addressbook.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141119152457_create_accounts.rb +11 -0
- data/spec/dummy/db/migrate/20141119152801_add_addressbook_account_id_to_user_table.addressbook.rb +12 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +13510 -0
- data/spec/dummy/log/test.log +1468 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/uploads/addressbook/contact/imported/test.csv +10 -0
- data/spec/dummy/public/uploads/addressbook/contact/imported/test.vcf +23 -0
- data/spec/dummy/spec/factories/accounts.rb +9 -0
- data/spec/dummy/spec/models/account_spec.rb +5 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/006961e21c4f6a44101d2e9587f863f4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/032ca99c7bed652dbad8de691558648d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/06b00b7743f1b8c8020fabbb5c63e13a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0765e86c020fb088284e8f45c584f8c6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1648d5d40aa02876f2cbb311ab2c4712 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/17405e31165e7d8129c846ceabaafec0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1dcb75c883fc0e57d08de7a76f0ada73 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/30f5fe3df78dce04aa1f998f6d790113 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4b14ea7024b3a7934c5cf77c17cc92aa +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/604356b7aab9d373aa02548bf52b266b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/69fcb234f5e891fcb7fbeb727a703968 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6ec3857048c9b608a152271ff3991df6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/786158650544be3da3cd56983ff6540f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/790fb0d33aad92cb9a1745822d4668aa +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7954e67edaec86854ad0d70dfdc1df99 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/816240bd34b73344a7ac901c29906f1d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8a8a4eebb0809e6e5a1d1dc83dafb50d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8e844acaef03b740a1d21aafa3030124 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/91d3ad598e6e79937286c98b2b259cee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/98e43302695126215ff9abe4b05eda56 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aa5e472ff34ac18d968ac316ca9caff2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aa9a9307e1b4596e0b92b403107a2cfb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aee3f8a82c799313c63b922ed8b0f975 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c1f56035111b730c0c3807bf5ca35251 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c497b90d7dd45d368ec4e83d97d0a2b9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d23b864a4a8239210d53e50644405687 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dee437547d5fb5fab72af8a8d8582d4d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e9553c97dc4fe95dc10736ee0475dc45 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ec3c091506a3d1ea73ac726b7ee9b3c2 +0 -0
- data/spec/fixtures/test.csv +10 -0
- data/spec/fixtures/test.vcf +23 -0
- data/spec/model/addressbook/account_spec.rb +33 -0
- data/spec/model/addressbook/contact_spec.rb +79 -0
- data/spec/model/addressbook/group_spec.rb +11 -0
- data/spec/model/addressbook/resource_spec.rb +10 -0
- data/spec/spec_helper.rb +65 -0
- metadata +517 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Addressbook
|
2
|
+
class Group < Resource
|
3
|
+
|
4
|
+
validates_presence_of :name
|
5
|
+
|
6
|
+
module RelationExtensions
|
7
|
+
def new(params = {})
|
8
|
+
params.merge!(original_params)
|
9
|
+
resource_class.new(params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
schema do
|
14
|
+
attribute 'name', :string
|
15
|
+
attribute 'description', :string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Addressbook
|
2
|
+
class PhotoUploader < BaseUploader
|
3
|
+
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
include CarrierWave::MiniMagick
|
7
|
+
|
8
|
+
# Process files as they are uploaded:
|
9
|
+
# process :scale => [1200, 300]
|
10
|
+
#
|
11
|
+
def scale(width, height)
|
12
|
+
resize_to_fill(width, height)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create different versions of your uploaded files:
|
16
|
+
version :thumb do
|
17
|
+
process :resize_to_fill => [100, 100]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
21
|
+
# For images you might use something like this:
|
22
|
+
def extension_white_list
|
23
|
+
%w(jpg jpeg gif png)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
|
3
|
+
module Addressbook
|
4
|
+
class Resource < ActiveResource::Base
|
5
|
+
|
6
|
+
include ActiveModel::Validations
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
cattr_accessor :static_headers
|
10
|
+
self.static_headers = headers
|
11
|
+
|
12
|
+
self.site = "http://localhost:3001/api/v1/"
|
13
|
+
self.user = "addressbook"
|
14
|
+
self.password = "defaultpw"
|
15
|
+
self.timeout = 180
|
16
|
+
|
17
|
+
def self.headers
|
18
|
+
new_headers = static_headers.clone
|
19
|
+
new_headers["access_id"] = ENV['addressbook_access_id']
|
20
|
+
new_headers["secret_key"] = ENV['addressbook_secret_key']
|
21
|
+
new_headers
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Addressbook
|
2
|
+
module Generators
|
3
|
+
class Addressbook::ControllersGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../../../../', __FILE__)
|
6
|
+
|
7
|
+
public_task :copy_controllers
|
8
|
+
|
9
|
+
desc "This generator copyies controllers to your project from engine.\n"
|
10
|
+
|
11
|
+
argument :name, required: false, default: nil, desc: "The scope to copy controllers to project"
|
12
|
+
|
13
|
+
desc << <<-eos
|
14
|
+
Example:
|
15
|
+
"rails g addressbook:controllers"
|
16
|
+
will copy all addressbook files (controllers and layouts)
|
17
|
+
|
18
|
+
"rails g addressbook:controllers addressbook"
|
19
|
+
will copy all addressbook controllers
|
20
|
+
|
21
|
+
"rails g addressbook:controllers addressbook/contacts"
|
22
|
+
will copy only contacts controllers
|
23
|
+
|
24
|
+
"rails g addressbook:controllers addressbook/groups"
|
25
|
+
will copy only groups controllers
|
26
|
+
|
27
|
+
"rails g addressbook:controllers application"
|
28
|
+
will copy addressbook application controller
|
29
|
+
eos
|
30
|
+
|
31
|
+
def copy_controllers
|
32
|
+
controller_directory name.nil? ? "" : name
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def controller_directory(name, _target_path = nil)
|
38
|
+
directory "app/controllers/#{name}", "app/controllers/#{name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Addressbook
|
2
|
+
module Generators
|
3
|
+
class Addressbook::InitializerGenerator < Rails::Generators::Base
|
4
|
+
def create_initializer_file
|
5
|
+
create_file "config/initializers/addressbook.rb", "Addressbook.user_class = 'Account'\nAddressbook::Resource.site = 'http://localhost:3001/api/v1/'\n\nAddressbook.aws_config = Addressbook::Contact.get :s3_credential rescue {} unless Rails.env.test?"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Addressbook
|
2
|
+
module Generators
|
3
|
+
class Addressbook::ViewsGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../../../../', __FILE__)
|
6
|
+
|
7
|
+
public_task :copy_views
|
8
|
+
|
9
|
+
desc "This generator copyies views to your project from engine.\n"
|
10
|
+
|
11
|
+
argument :name, required: false, default: nil, desc: "The scope to copy views to project"
|
12
|
+
|
13
|
+
desc << <<-eos
|
14
|
+
Example:
|
15
|
+
"rails g addressbook:views"
|
16
|
+
will copy all addressbook files (views and layouts)
|
17
|
+
|
18
|
+
"rails g addressbook:views addressbook"
|
19
|
+
will copy all addressbook views
|
20
|
+
|
21
|
+
"rails g addressbook:views addressbook/contacts"
|
22
|
+
will copy only contacts views
|
23
|
+
|
24
|
+
"rails g addressbook:views addressbook/groups"
|
25
|
+
will copy only groups views
|
26
|
+
|
27
|
+
"rails g addressbook:views layouts"
|
28
|
+
will copy addressbook layouts
|
29
|
+
eos
|
30
|
+
|
31
|
+
def copy_views
|
32
|
+
view_directory name.nil? ? "" : name
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def view_directory(name, _target_path = nil)
|
38
|
+
directory "app/views/#{name}", "app/views/#{name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Addressbook
|
4
|
+
describe ContactsController do
|
5
|
+
routes { Addressbook::Engine.routes }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@contacts_json = [{ first_name: Faker::Name.first_name, last_name: Faker::Name.last_name }].to_json
|
9
|
+
@account_json = { id: 1, email: "test@test.com", name: "Alexander K." }.to_json
|
10
|
+
|
11
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
12
|
+
mock.post "/api/v1/accounts.json", { "Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Content-Type"=>"application/json", "access_id"=>nil, "secret_key"=>nil }, @account_json, 201, "Location" => "/api/v1/accounts/1.json"
|
13
|
+
mock.get "/api/v1/contacts.json?account_id=1&action=index&controller=addressbook%2Fcontacts", {"Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Accept"=>"application/json", "access_id"=>nil, "secret_key"=>nil}, @contacts_json
|
14
|
+
mock.get "/api/v1/contacts.json?account_id=1", {"Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Accept"=>"application/json", "access_id"=>nil, "secret_key"=>nil}, @contacts_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "GET 'index'" do
|
19
|
+
it "should render index" do
|
20
|
+
get :index
|
21
|
+
|
22
|
+
should render_template :index
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "GET 'new'" do
|
27
|
+
it "should render new" do
|
28
|
+
get :new
|
29
|
+
|
30
|
+
should render_template :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "POST 'create'" do
|
35
|
+
it "should redirect to contacts path with validation" do
|
36
|
+
Addressbook::Contact.any_instance.should_receive(:save).and_return(true)
|
37
|
+
|
38
|
+
post :create
|
39
|
+
|
40
|
+
should redirect_to contacts_path
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should render new with invalidation" do
|
44
|
+
Addressbook::Contact.any_instance.should_receive(:save).and_return(false)
|
45
|
+
|
46
|
+
post :create
|
47
|
+
|
48
|
+
should render_template :new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GET 'edit'" do
|
53
|
+
before :each do
|
54
|
+
@contact = mock_model Contact
|
55
|
+
Addressbook::Contact.should_receive(:find).and_return(@contact)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should render edit" do
|
59
|
+
get :edit, id: @contact.id
|
60
|
+
|
61
|
+
should render_template :edit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "PUT 'update'" do
|
66
|
+
before :each do
|
67
|
+
@contact = mock_model Contact
|
68
|
+
Addressbook::Contact.should_receive(:find).and_return(@contact)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should redirect to contacts path with validation" do
|
72
|
+
@contact.should_receive(:update_attributes).and_return(true)
|
73
|
+
|
74
|
+
put :update, id: @contact.id
|
75
|
+
|
76
|
+
should redirect_to contacts_path
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should render edit with invalidation" do
|
80
|
+
@contact.should_receive(:update_attributes).and_return(false)
|
81
|
+
|
82
|
+
put :update, id: @contact.id
|
83
|
+
|
84
|
+
should render_template :edit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "DELETE 'destroy'" do
|
89
|
+
before :each do
|
90
|
+
@contact = mock_model Contact
|
91
|
+
Addressbook::Contact.should_receive(:find).and_return(@contact)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should render destroy" do
|
95
|
+
delete :destroy, id: @contact.id, format: :js
|
96
|
+
|
97
|
+
should render_template :destroy
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "POST 'import_vcard'" do
|
102
|
+
context "valid vcard file" do
|
103
|
+
before do
|
104
|
+
@upload_file = ActionDispatch::Http::UploadedFile.new({
|
105
|
+
:original_filename => 'test.vcf',
|
106
|
+
:type => 'text/vcard',
|
107
|
+
:tempfile => File.new(fixture_path + '/test.vcf')
|
108
|
+
})
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should redirect to contacts path after importing" do
|
112
|
+
post 'import_vcard', vcard: @upload_file
|
113
|
+
|
114
|
+
should redirect_to contacts_path
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "invalid vcard file" do
|
119
|
+
before do
|
120
|
+
@upload_file = ActionDispatch::Http::UploadedFile.new({
|
121
|
+
:original_filename => 'invalid_vcard',
|
122
|
+
:type => 'text/vcard',
|
123
|
+
:tempfile => File.new(fixture_path + '/test.vcf')
|
124
|
+
})
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should redirect to contacts path without importing" do
|
128
|
+
post 'import_vcard', vcard: @upload_file
|
129
|
+
|
130
|
+
should redirect_to contacts_path
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "POST 'import_csv'" do
|
136
|
+
context "valid csv file" do
|
137
|
+
before do
|
138
|
+
@upload_file = ActionDispatch::Http::UploadedFile.new({
|
139
|
+
:original_filename => 'test.vcf',
|
140
|
+
:type => 'text/csv',
|
141
|
+
:tempfile => File.new(fixture_path + '/test.vcf')
|
142
|
+
})
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should redirect to contacts path after importing" do
|
146
|
+
post 'import_csv', csv: @upload_file
|
147
|
+
|
148
|
+
should redirect_to contacts_path
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "invalid csv file" do
|
153
|
+
before do
|
154
|
+
@upload_file = ActionDispatch::Http::UploadedFile.new({
|
155
|
+
:original_filename => 'invalid_csv',
|
156
|
+
:type => 'text/csv',
|
157
|
+
:tempfile => File.new(fixture_path + '/test.vcf')
|
158
|
+
})
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should redirect to contacts path without importing" do
|
162
|
+
post 'import_csv', csv: @upload_file
|
163
|
+
|
164
|
+
should redirect_to contacts_path
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Addressbook
|
4
|
+
describe GroupsController do
|
5
|
+
routes { Addressbook::Engine.routes }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@groups_json = [{ name: Faker::Lorem.word, description: Faker::Lorem.sentence }].to_json
|
9
|
+
@account_json = { id: 1, email: "test@test.com", name: "Alexander K." }.to_json
|
10
|
+
|
11
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
12
|
+
mock.post "/api/v1/accounts.json", { "Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Content-Type"=>"application/json", "access_id"=>nil, "secret_key"=>nil }, @account_json, 201, "Location" => "/api/v1/accounts/1.json"
|
13
|
+
mock.get "/api/v1/groups.json?account_id=1&action=index&controller=addressbook%2Fgroups", {"Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Accept"=>"application/json", "access_id"=>nil, "secret_key"=>nil}, @groups_json
|
14
|
+
mock.get "/api/v1/groups.json?account_id=1", {"Authorization"=>"Basic YWRkcmVzc2Jvb2s6ZGVmYXVsdHB3", "Accept"=>"application/json", "access_id"=>nil, "secret_key"=>nil}, @groups_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "GET 'index'" do
|
19
|
+
it "should render index" do
|
20
|
+
get :index
|
21
|
+
|
22
|
+
should render_template :index
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "GET 'new'" do
|
27
|
+
it "should render new" do
|
28
|
+
get :new
|
29
|
+
|
30
|
+
should render_template :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "POST 'create'" do
|
35
|
+
before :each do
|
36
|
+
request.env["HTTP_REFERER"] = root_url
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should redirect to groups path with validation" do
|
40
|
+
Addressbook::Group.any_instance.should_receive(:save).and_return(true)
|
41
|
+
|
42
|
+
post :create
|
43
|
+
|
44
|
+
should redirect_to root_path
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should render new with invalidation" do
|
48
|
+
Addressbook::Group.any_instance.should_receive(:save).and_return(false)
|
49
|
+
|
50
|
+
post :create
|
51
|
+
|
52
|
+
should render_template :new
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "GET 'edit'" do
|
57
|
+
before :each do
|
58
|
+
@group = mock_model Group
|
59
|
+
Addressbook::Group.should_receive(:find).and_return(@group)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should render edit" do
|
63
|
+
get :edit, id: @group.id
|
64
|
+
|
65
|
+
should render_template :edit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "PUT 'update'" do
|
70
|
+
before :each do
|
71
|
+
@group = mock_model Group
|
72
|
+
Addressbook::Group.should_receive(:find).and_return(@group)
|
73
|
+
request.env["HTTP_REFERER"] = root_url
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should redirect to groups path with validation" do
|
77
|
+
@group.should_receive(:update_attributes).and_return(true)
|
78
|
+
|
79
|
+
put :update, id: @group.id
|
80
|
+
|
81
|
+
should redirect_to root_path
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should render edit with invalidation" do
|
85
|
+
@group.should_receive(:update_attributes).and_return(false)
|
86
|
+
|
87
|
+
put :update, id: @group.id
|
88
|
+
|
89
|
+
should render_template :edit
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "DELETE 'destroy'" do
|
94
|
+
before :each do
|
95
|
+
@group = mock_model Group
|
96
|
+
Addressbook::Group.should_receive(:find).and_return(@group)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should render destroy" do
|
100
|
+
delete :destroy, id: @group.id, format: :js
|
101
|
+
|
102
|
+
should render_template :destroy
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|