dune-admin 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +14 -0
- data/app/assets/images/dune/admin/.gitkip +0 -0
- data/app/assets/javascripts/dune-admin.js +2 -0
- data/app/assets/javascripts/dune/admin/admin.js.coffee +11 -0
- data/app/assets/javascripts/dune/admin/channels/new.js.coffee +14 -0
- data/app/assets/javascripts/dune/admin/modules/sort.js.coffee +44 -0
- data/app/assets/stylesheets/dune/admin/.gitkip +0 -0
- data/app/assets/stylesheets/dune/admin/admin.sass +37 -0
- data/app/assets/stylesheets/neighborly-admin.sass +1 -0
- data/app/controllers/dune/admin/base_controller.rb +25 -0
- data/app/controllers/dune/admin/channels/members_controller.rb +46 -0
- data/app/controllers/dune/admin/channels_controller.rb +49 -0
- data/app/controllers/dune/admin/contacts_controller.rb +9 -0
- data/app/controllers/dune/admin/contributions_controller.rb +33 -0
- data/app/controllers/dune/admin/dashboard_controller.rb +8 -0
- data/app/controllers/dune/admin/financials_controller.rb +33 -0
- data/app/controllers/dune/admin/press_assets_controller.rb +26 -0
- data/app/controllers/dune/admin/projects_controller.rb +80 -0
- data/app/controllers/dune/admin/reports/base_controller.rb +8 -0
- data/app/controllers/dune/admin/reports/contribution_reports_controller.rb +8 -0
- data/app/controllers/dune/admin/reports/funding_raised_per_project_reports_controller.rb +4 -0
- data/app/controllers/dune/admin/reports/statistics_controller.rb +5 -0
- data/app/controllers/dune/admin/tags_controller.rb +35 -0
- data/app/controllers/dune/admin/users_controller.rb +27 -0
- data/app/models/dune/admin/.gitkip +0 -0
- data/app/models/dune/admin/contribution_concern.rb +23 -0
- data/app/models/dune/admin/funding_raised_per_project_report.rb +5 -0
- data/app/models/dune/admin/project_concern.rb +41 -0
- data/app/models/dune/admin/statistics.rb +5 -0
- data/app/models/dune/admin/user_concern.rb +13 -0
- data/app/policies/dune/admin/admin_policy.rb +7 -0
- data/app/views/dune/admin/.gitkip +0 -0
- data/app/views/dune/admin/channels/_form.html.slim +98 -0
- data/app/views/dune/admin/channels/edit.html.slim +7 -0
- data/app/views/dune/admin/channels/index.html.slim +58 -0
- data/app/views/dune/admin/channels/members/index.html.slim +38 -0
- data/app/views/dune/admin/channels/members/new.html.slim +11 -0
- data/app/views/dune/admin/channels/new.html.slim +7 -0
- data/app/views/dune/admin/contacts/index.html.slim +32 -0
- data/app/views/dune/admin/contacts/show.html.slim +34 -0
- data/app/views/dune/admin/contributions/index.html.slim +138 -0
- data/app/views/dune/admin/dashboard/index.html.slim +65 -0
- data/app/views/dune/admin/financials/index.html.slim +88 -0
- data/app/views/dune/admin/layouts/_menu.html.slim +11 -0
- data/app/views/dune/admin/press_assets/_form.html.slim +11 -0
- data/app/views/dune/admin/press_assets/edit.html.slim +9 -0
- data/app/views/dune/admin/press_assets/index.html.slim +32 -0
- data/app/views/dune/admin/press_assets/new.html.slim +9 -0
- data/app/views/dune/admin/projects/index.html.slim +151 -0
- data/app/views/dune/admin/projects/populate_contribution.html.slim +48 -0
- data/app/views/dune/admin/tags/_form.html.slim +4 -0
- data/app/views/dune/admin/tags/edit.html.slim +7 -0
- data/app/views/dune/admin/tags/index.html.slim +44 -0
- data/app/views/dune/admin/tags/new.html.slim +7 -0
- data/app/views/dune/admin/users/index.html.slim +68 -0
- data/bin/rails +8 -0
- data/config/locales/en.yml +274 -0
- data/config/routes.rb +47 -0
- data/db/migrate/20141005184741_create_dune_admin_funding_raised_per_project_reports.rb +21 -0
- data/db/migrate/20141005191509_create_dune_admin_statistics.rb +55 -0
- data/dune-admin.gemspec +27 -0
- data/lib/dune/admin.rb +10 -0
- data/lib/dune/admin/engine.rb +13 -0
- data/lib/dune/admin/version.rb +5 -0
- data/spec/controllers/dune/admin/channels/members_controller_spec.rb +119 -0
- data/spec/controllers/dune/admin/channels_controller_spec.rb +161 -0
- data/spec/controllers/dune/admin/contacts_controller_spec.rb +23 -0
- data/spec/controllers/dune/admin/cotributions_controller_spec.rb +130 -0
- data/spec/controllers/dune/admin/dasboard_controller_spec.rb +18 -0
- data/spec/controllers/dune/admin/financials_controller_spec.rb +45 -0
- data/spec/controllers/dune/admin/press_assets_controller_spec.rb +138 -0
- data/spec/controllers/dune/admin/projects_controller_spec.rb +201 -0
- data/spec/controllers/dune/admin/tags_controller_spec.rb +137 -0
- data/spec/controllers/dune/admin/users_controller_spec.rb +30 -0
- data/spec/models/dune/admin/contribution_concern_spec.rb +19 -0
- data/spec/models/dune/admin/project_concern_spec.rb +56 -0
- data/spec/models/dune/admin/user_concern_spec.rb +65 -0
- data/spec/policies/dune/admin/admin_policy_spec.rb +22 -0
- data/spec/spec_helper.rb +40 -0
- metadata +237 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::ContactsController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
let(:current_user){ create(:user, admin: true) }
|
|
6
|
+
let(:contact) { create(:contact) }
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
controller.stub(:current_user).and_return(current_user)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "GET 'index'" do
|
|
13
|
+
before { get :index }
|
|
14
|
+
it { expect(response).to be_success }
|
|
15
|
+
it { expect(assigns(:contacts)).to eq [contact] }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "GET 'show'" do
|
|
19
|
+
before { get :show, id: contact }
|
|
20
|
+
it { expect(response).to be_success }
|
|
21
|
+
it { expect(assigns(:contact)).to eq contact }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::ContributionsController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
subject{ response }
|
|
6
|
+
let(:admin) { create(:user, admin: true) }
|
|
7
|
+
let(:unconfirmed_contribution) { create(:contribution) }
|
|
8
|
+
let(:current_user){ admin }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
controller.stub(:current_user).and_return(current_user)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'PUT confirm' do
|
|
15
|
+
let(:contribution) { create(:contribution) }
|
|
16
|
+
subject { contribution.confirmed? }
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
put :confirm, id: contribution.id, locale: :pt
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it do
|
|
23
|
+
contribution.reload
|
|
24
|
+
should be_true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'PUT push_to_trash' do
|
|
29
|
+
let(:contribution) { create(:contribution, state: 'pending') }
|
|
30
|
+
subject { contribution.deleted? }
|
|
31
|
+
|
|
32
|
+
before do
|
|
33
|
+
put :push_to_trash, id: contribution.id, locale: :pt
|
|
34
|
+
contribution.reload
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it { should be_true }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'PUT hide' do
|
|
41
|
+
let(:contribution) { create(:contribution, state: 'confirmed') }
|
|
42
|
+
subject { contribution.refunded_and_canceled? }
|
|
43
|
+
|
|
44
|
+
before do
|
|
45
|
+
controller.stub(:current_user).and_return(admin)
|
|
46
|
+
put :hide, id: contribution.id, locale: :pt
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it do
|
|
50
|
+
contribution.reload
|
|
51
|
+
should be_true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'PUT refund' do
|
|
56
|
+
let(:contribution) { create(:contribution, state: 'confirmed') }
|
|
57
|
+
subject { contribution.refunded? }
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
put :refund, id: contribution.id, locale: :pt
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it do
|
|
64
|
+
contribution.reload
|
|
65
|
+
should be_true
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe 'PUT pendent' do
|
|
70
|
+
let(:contribution) { create(:contribution, state: 'confirmed') }
|
|
71
|
+
subject { contribution.confirmed? }
|
|
72
|
+
|
|
73
|
+
before do
|
|
74
|
+
put :pendent, id: contribution.id, locale: :pt
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it do
|
|
78
|
+
contribution.reload
|
|
79
|
+
should be_false
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe 'PUT cancel' do
|
|
84
|
+
let(:contribution) { create(:contribution, state: 'confirmed') }
|
|
85
|
+
subject { contribution.canceled? }
|
|
86
|
+
|
|
87
|
+
before do
|
|
88
|
+
put :cancel, id: contribution.id, locale: :pt
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it do
|
|
92
|
+
contribution.reload
|
|
93
|
+
should be_true
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "GET index" do
|
|
98
|
+
context "when I'm not logged in" do
|
|
99
|
+
let(:current_user){ nil }
|
|
100
|
+
before do
|
|
101
|
+
get :index, :locale => :pt
|
|
102
|
+
end
|
|
103
|
+
it{ should redirect_to '/login' }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context "when I'm logged as admin" do
|
|
107
|
+
before do
|
|
108
|
+
get :index, :locale => :pt
|
|
109
|
+
end
|
|
110
|
+
its(:status){ should == 200 }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe '.collection' do
|
|
115
|
+
let(:contribution) { create(:contribution, payer_email: 'foo@foo.com') }
|
|
116
|
+
context "when there is a match" do
|
|
117
|
+
before do
|
|
118
|
+
get :index, locale: :pt, payer_email_contains: 'foo@foo.com'
|
|
119
|
+
end
|
|
120
|
+
it{ assigns(:contributions).should eq([contribution]) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "when there is no match" do
|
|
124
|
+
before do
|
|
125
|
+
get :index, locale: :pt, payer_email_contains: '2foo@foo.com'
|
|
126
|
+
end
|
|
127
|
+
it{ assigns(:contributions).should eq([]) }
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::DashboardController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
subject{ response }
|
|
6
|
+
let(:admin) { create(:user, admin: true) }
|
|
7
|
+
before do
|
|
8
|
+
controller.stub(:current_user).and_return(admin)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "GET index" do
|
|
12
|
+
before do
|
|
13
|
+
get :index
|
|
14
|
+
end
|
|
15
|
+
it{ should render_template :index }
|
|
16
|
+
its(:status){ should == 200 }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::FinancialsController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
let(:admin) { create(:user, admin: true) }
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
controller.stub(:current_user).and_return(admin)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "GET index" do
|
|
12
|
+
context 'as html format' do
|
|
13
|
+
before { get :index, locale: 'pt' }
|
|
14
|
+
|
|
15
|
+
it{ should render_template :index }
|
|
16
|
+
its(:status){ should == 200 }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'as csv format' do
|
|
20
|
+
before { get :index, format: :csv, locale: 'pt' }
|
|
21
|
+
|
|
22
|
+
it{ expect(response.content_type).to eq 'text/csv' }
|
|
23
|
+
its(:status){ should == 200 }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '.collection' do
|
|
28
|
+
let(:project) { create(:project, name: 'Foo Bar Project') }
|
|
29
|
+
|
|
30
|
+
context "when there is a match" do
|
|
31
|
+
before do
|
|
32
|
+
get :index, locale: :pt, name_contains: 'Foo Bar Project'
|
|
33
|
+
end
|
|
34
|
+
it{ assigns(:projects).should eq([project]) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when there is no match" do
|
|
38
|
+
before do
|
|
39
|
+
get :index, locale: :pt, name_contains: 'Other search'
|
|
40
|
+
end
|
|
41
|
+
it{ assigns(:projects).should eq([]) }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::PressAssetsController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
subject{ response }
|
|
6
|
+
let(:admin) { create(:user, admin: true) }
|
|
7
|
+
let(:current_user){ admin }
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
controller.stub(:current_user).and_return(current_user)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "GET index" do
|
|
14
|
+
context "when I'm not logged in" do
|
|
15
|
+
let(:current_user){ nil }
|
|
16
|
+
before do
|
|
17
|
+
get :index
|
|
18
|
+
end
|
|
19
|
+
it{ should redirect_to '/login' }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when I'm logged as admin" do
|
|
23
|
+
before do
|
|
24
|
+
get :index
|
|
25
|
+
end
|
|
26
|
+
its(:status){ should == 200 }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "GET edit" do
|
|
31
|
+
let(:press_asset) { create(:press_asset) }
|
|
32
|
+
context "when I'm not logged in" do
|
|
33
|
+
let(:current_user){ nil }
|
|
34
|
+
before do
|
|
35
|
+
get :edit, id: press_asset
|
|
36
|
+
end
|
|
37
|
+
it{ should redirect_to '/login' }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when I'm logged as admin" do
|
|
41
|
+
before do
|
|
42
|
+
get :edit, id: press_asset
|
|
43
|
+
end
|
|
44
|
+
its(:status){ should == 200 }
|
|
45
|
+
|
|
46
|
+
it 'should assigns the correct resource' do
|
|
47
|
+
expect(assigns(:press_asset)).to eq press_asset
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "PUT update" do
|
|
53
|
+
let(:press_asset) { create(:press_asset) }
|
|
54
|
+
|
|
55
|
+
context "when I'm not logged in" do
|
|
56
|
+
let(:current_user){ nil }
|
|
57
|
+
before do
|
|
58
|
+
put :update, id: press_asset
|
|
59
|
+
end
|
|
60
|
+
it{ should redirect_to '/login' }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "when I'm logged as admin" do
|
|
64
|
+
before do
|
|
65
|
+
put :update, id: press_asset, press_asset: { title: 'updated title!' }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it{ should redirect_to press_assets_path }
|
|
69
|
+
|
|
70
|
+
it 'should update press_asset title' do
|
|
71
|
+
expect(press_asset.reload.title).to eq 'updated title!'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "GET new" do
|
|
77
|
+
context "when I'm not logged in" do
|
|
78
|
+
let(:current_user){ nil }
|
|
79
|
+
before do
|
|
80
|
+
get :new
|
|
81
|
+
end
|
|
82
|
+
it{ should redirect_to '/login' }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when I'm logged as admin" do
|
|
86
|
+
before do
|
|
87
|
+
get :new
|
|
88
|
+
end
|
|
89
|
+
its(:status){ should == 200 }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe "POST create" do
|
|
94
|
+
context "when I'm not logged in" do
|
|
95
|
+
let(:current_user){ nil }
|
|
96
|
+
before do
|
|
97
|
+
post :create
|
|
98
|
+
end
|
|
99
|
+
it{ should redirect_to '/login' }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "when I'm logged as admin" do
|
|
103
|
+
before do
|
|
104
|
+
post :create, press_asset: build(:press_asset).attributes.merge(image: Rack::Test::UploadedFile.new("#{Rails.root}/spec/fixtures/image.png"))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it{ should redirect_to press_assets_path }
|
|
108
|
+
|
|
109
|
+
it 'should create a new press_asset' do
|
|
110
|
+
expect(PressAsset.all).to have(1).press_asset
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe "DELETE destroy" do
|
|
116
|
+
let(:press_asset) { create(:press_asset) }
|
|
117
|
+
|
|
118
|
+
context "when I'm not logged in" do
|
|
119
|
+
let(:current_user){ nil }
|
|
120
|
+
before do
|
|
121
|
+
delete :destroy, id: press_asset
|
|
122
|
+
end
|
|
123
|
+
it{ should redirect_to '/login' }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "when I'm logged as admin" do
|
|
127
|
+
before { delete :destroy, id: press_asset }
|
|
128
|
+
|
|
129
|
+
it{ should redirect_to press_assets_path }
|
|
130
|
+
|
|
131
|
+
it 'should destroy the press_asset' do
|
|
132
|
+
expect{ press_asset.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Dune::Admin::ProjectsController do
|
|
4
|
+
routes { Dune::Admin::Engine.routes }
|
|
5
|
+
subject{ response }
|
|
6
|
+
let(:admin) { create(:user, admin: true) }
|
|
7
|
+
let(:current_user){ admin }
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
controller.stub(:current_user).and_return(current_user)
|
|
11
|
+
request.env['HTTP_REFERER'] = projects_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'PUT launch' do
|
|
15
|
+
let(:project) { create(:project, state: 'draft') }
|
|
16
|
+
subject { project.online? }
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
put :launch, id: project, locale: :pt
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it do
|
|
23
|
+
project.reload
|
|
24
|
+
should be_true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'PUT reject' do
|
|
29
|
+
let(:project) { create(:project, state: 'draft') }
|
|
30
|
+
subject { project.rejected? }
|
|
31
|
+
|
|
32
|
+
before do
|
|
33
|
+
put :reject, id: project, locale: :pt
|
|
34
|
+
project.reload
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it { should be_true }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'PUT push_to_draft' do
|
|
41
|
+
let(:project) { create(:project, state: 'online') }
|
|
42
|
+
subject { project.draft? }
|
|
43
|
+
|
|
44
|
+
before do
|
|
45
|
+
controller.stub(:current_user).and_return(admin)
|
|
46
|
+
put :push_to_draft, id: project, locale: :pt
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it do
|
|
50
|
+
project.reload
|
|
51
|
+
should be_true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "GET index" do
|
|
56
|
+
context "when I'm not logged in" do
|
|
57
|
+
let(:current_user){ nil }
|
|
58
|
+
before do
|
|
59
|
+
get :index, locale: :pt
|
|
60
|
+
end
|
|
61
|
+
it{ should redirect_to '/login' }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when I'm logged as admin" do
|
|
65
|
+
before do
|
|
66
|
+
get :index, locale: :pt
|
|
67
|
+
end
|
|
68
|
+
its(:status){ should == 200 }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '.collection' do
|
|
73
|
+
let(:project) { create(:project, name: 'Project for search') }
|
|
74
|
+
context "when there is a match" do
|
|
75
|
+
before do
|
|
76
|
+
get :index, locale: :pt, pg_search: 'Project for search'
|
|
77
|
+
end
|
|
78
|
+
it{ assigns(:projects).should eq([project]) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "when there is no match" do
|
|
82
|
+
before do
|
|
83
|
+
get :index, locale: :pt, pg_search: 'Foo Bar'
|
|
84
|
+
end
|
|
85
|
+
it{ assigns(:projects).should eq([]) }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "DELETE destroy" do
|
|
90
|
+
let(:project) { create(:project, state: 'draft') }
|
|
91
|
+
|
|
92
|
+
context "when I'm not logged in" do
|
|
93
|
+
let(:current_user){ nil }
|
|
94
|
+
before do
|
|
95
|
+
delete :destroy, id: project, locale: :pt
|
|
96
|
+
end
|
|
97
|
+
it{ should redirect_to '/login' }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "when I'm logged as admin" do
|
|
101
|
+
before do
|
|
102
|
+
delete :destroy, id: project, locale: :pt
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
its(:status){ should redirect_to projects_path }
|
|
106
|
+
|
|
107
|
+
it 'should change state to deleted' do
|
|
108
|
+
expect(project.reload.deleted?).to be_true
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "POST populate" do
|
|
114
|
+
let(:project) { create(:project, state: 'online') }
|
|
115
|
+
|
|
116
|
+
context "when I'm not logged in" do
|
|
117
|
+
let(:current_user){ nil }
|
|
118
|
+
before do
|
|
119
|
+
post :populate, id: project
|
|
120
|
+
end
|
|
121
|
+
it{ should redirect_to '/login' }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "when I'm logged as admin" do
|
|
125
|
+
let(:reward) { create(:reward, project: project) }
|
|
126
|
+
|
|
127
|
+
shared_examples_for 'create the contribution' do
|
|
128
|
+
subject { project.contributions.first }
|
|
129
|
+
|
|
130
|
+
it 'should create the contribution' do
|
|
131
|
+
expect(subject).to_not be_nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
it 'should assign the reward the contribution' do
|
|
136
|
+
expect(subject.reward).to eq reward
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'should set the payment method ' do
|
|
140
|
+
expect(subject.payment_method).to eq 'PrePopulate'
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'should set the contribution as confirmed' do
|
|
144
|
+
expect(subject.confirmed?).to be_true
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'should set the contribution as anonymous' do
|
|
148
|
+
expect(subject.anonymous).to be_true
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it{ should redirect_to populate_contribution_project_path(project) }
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context 'existing user' do
|
|
155
|
+
before do
|
|
156
|
+
post :populate, id: project, user: { id: admin.id }, contribution: { reward_id: reward.id, value: reward.minimum_value, anonymous: true }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it_behaves_like 'create the contribution'
|
|
160
|
+
|
|
161
|
+
it 'should assign the user to the contribution' do
|
|
162
|
+
expect(project.contributions.first.user).to eq admin
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context 'new user' do
|
|
167
|
+
before do
|
|
168
|
+
post :populate, id: project, user: { name: 'New user', profile_type: 'organization' }, contribution: { reward_id: reward.id, value: reward.minimum_value, anonymous: true }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it_behaves_like 'create the contribution'
|
|
172
|
+
|
|
173
|
+
context 'create the user' do
|
|
174
|
+
subject { project.contributions.first.user }
|
|
175
|
+
|
|
176
|
+
it 'should create the iser' do
|
|
177
|
+
expect(subject).to_not be_nil
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'should set the user name' do
|
|
181
|
+
expect(subject.name).to eq 'New user'
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'should create an email with populate.user' do
|
|
185
|
+
expect(subject.email).to match(/@populate.user/)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context 'with error' do
|
|
191
|
+
before do
|
|
192
|
+
post :populate, id: project, user: { }, contribution: { }
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it{ should render_template 'populate_contribution' }
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|