Commit 433e428490896383f857320658863eaed4e9898a
Exists in
master
and in
1 other branch
Merge branch 'master' of https://github.com/errbit/errbit
Showing
4 changed files
with
165 additions
and
3 deletions
Show diff stats
README.md
| @@ -191,7 +191,7 @@ heroku run rake db:seed | @@ -191,7 +191,7 @@ heroku run rake db:seed | ||
| 191 | * You may want to enable the deployment hook for heroku : | 191 | * You may want to enable the deployment hook for heroku : |
| 192 | 192 | ||
| 193 | ```bash | 193 | ```bash |
| 194 | -heroku addons:add deployhooks:http url="http://YOUR_ERRBIT_HOST/deploys.txt?api_key=YOUR_API_KEY" | 194 | +heroku addons:add deployhooks:http --url="http://YOUR_ERRBIT_HOST/deploys.txt?api_key=YOUR_API_KEY" |
| 195 | ``` | 195 | ``` |
| 196 | 196 | ||
| 197 | * Enjoy! | 197 | * Enjoy! |
| @@ -233,6 +233,43 @@ You can change the requested account permissions by setting `github_access_scope | @@ -233,6 +233,43 @@ You can change the requested account permissions by setting `github_access_scope | ||
| 233 | </table> | 233 | </table> |
| 234 | 234 | ||
| 235 | 235 | ||
| 236 | +### GitHub authentication when served on Heroku | ||
| 237 | + | ||
| 238 | +You will need to set up Heroku variables accordingly as described in [Configuring GitHub authentication](#configuring-github-authentication): | ||
| 239 | + | ||
| 240 | +* GITHUB_AUTHENTICATION | ||
| 241 | + | ||
| 242 | +```bash | ||
| 243 | +heroku config:add GITHUB_AUTHENTICATION=true | ||
| 244 | +``` | ||
| 245 | + | ||
| 246 | +* GITHUB_CLIENT_ID | ||
| 247 | + | ||
| 248 | +```bash | ||
| 249 | +heroku config:add GITHUB_CLIENT_ID=the_client_id_provided_by_GitHub | ||
| 250 | +``` | ||
| 251 | + | ||
| 252 | +* GITHUB_SECRET | ||
| 253 | + | ||
| 254 | +```bash | ||
| 255 | +heroku config:add GITHUB_SECRET=the_secret_provided_by_GitHub | ||
| 256 | +``` | ||
| 257 | + | ||
| 258 | +* GITHUB_ACCESS_SCOPE - set only one scope `repo` or `public_repo`. If you really need to put more than one, separate them with comma. | ||
| 259 | + | ||
| 260 | +```bash | ||
| 261 | +heroku config:add GITHUB_ACCESS_SCOPE=repo,public_repo | ||
| 262 | +``` | ||
| 263 | + | ||
| 264 | +__Note__: To avoid restarting your Heroku app 4 times you can set Heroku variables in a single command, i.e: | ||
| 265 | + | ||
| 266 | +```bash | ||
| 267 | +heroku config:add GITHUB_AUTHENTICATION=true \ | ||
| 268 | +GITHUB_CLIENT_ID=the_client_id_provided_by_GitHub \ | ||
| 269 | +GITHUB_SECRET=the_secret_provided_by_GitHub \ | ||
| 270 | +GITHUB_ACCESS_SCOPE=repo,public_repo | ||
| 271 | +``` | ||
| 272 | + | ||
| 236 | ### Configuring LDAP authentication: | 273 | ### Configuring LDAP authentication: |
| 237 | 274 | ||
| 238 | * In `config/config.yml`, set `user_has_username` to `true` | 275 | * In `config/config.yml`, set `user_has_username` to `true` |
app/controllers/errs_controller.rb
| @@ -114,8 +114,8 @@ class ErrsController < ApplicationController | @@ -114,8 +114,8 @@ class ErrsController < ApplicationController | ||
| 114 | end | 114 | end |
| 115 | 115 | ||
| 116 | def destroy_several | 116 | def destroy_several |
| 117 | - @selected_problems.each(&:destroy) | ||
| 118 | - flash[:notice] = "#{pluralize(@selected_problems.count, 'err has', 'errs have')} been deleted." | 117 | + nb_problem_destroy = ProblemDestroy.execute(@selected_problems) |
| 118 | + flash[:notice] = "#{pluralize(nb_problem_destroy, 'err has', 'errs have')} been deleted." | ||
| 119 | redirect_to :back | 119 | redirect_to :back |
| 120 | end | 120 | end |
| 121 | 121 |
| @@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
| 1 | +class ProblemDestroy | ||
| 2 | + | ||
| 3 | + attr_reader :problem | ||
| 4 | + | ||
| 5 | + def initialize(problem) | ||
| 6 | + @problem = problem | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def execute | ||
| 10 | + delete_errs | ||
| 11 | + delete_comments | ||
| 12 | + problem.delete | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + ## | ||
| 16 | + # Destroy all problem pass in args | ||
| 17 | + # | ||
| 18 | + # @params [ Array[Problem] ] problems the list of problem need to be delete | ||
| 19 | + # can be a single Problem | ||
| 20 | + # @return [ Integer ] | ||
| 21 | + # the number of problem destroy | ||
| 22 | + # | ||
| 23 | + def self.execute(problems) | ||
| 24 | + Array(problems).each{ |problem| | ||
| 25 | + ProblemDestroy.new(problem).execute | ||
| 26 | + }.count | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + private | ||
| 30 | + | ||
| 31 | + def errs_id | ||
| 32 | + problem.errs.only(:id).map(&:id) | ||
| 33 | + end | ||
| 34 | + | ||
| 35 | + def comments_id | ||
| 36 | + problem.comments.only(:id).map(&:id) | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + def delete_errs | ||
| 40 | + Err.collection.remove(:_id => { '$in' => errs_id }) | ||
| 41 | + Notice.collection.remove(:err_id => { '$in' => errs_id }) | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + def delete_comments | ||
| 45 | + Comment.collection.remove(:_id => { '$in' => comments_id }) | ||
| 46 | + end | ||
| 47 | + | ||
| 48 | +end |
| @@ -0,0 +1,77 @@ | @@ -0,0 +1,77 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe ProblemDestroy do | ||
| 4 | + let(:problem_destroy) { | ||
| 5 | + ProblemDestroy.new(problem) | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + context "in unit way" do | ||
| 9 | + let(:problem) { | ||
| 10 | + problem = Problem.new() | ||
| 11 | + problem.stub(:errs).and_return(mock(:criteria, :only => [err_1, err_2])) | ||
| 12 | + problem.stub(:comments).and_return(mock(:criteria, :only => [comment_1, comment_2])) | ||
| 13 | + problem.stub(:delete) | ||
| 14 | + problem | ||
| 15 | + } | ||
| 16 | + let(:err_1) { Err.new } | ||
| 17 | + let(:err_2) { Err.new } | ||
| 18 | + | ||
| 19 | + let(:comment_1) { Comment.new } | ||
| 20 | + let(:comment_2) { Comment.new } | ||
| 21 | + | ||
| 22 | + describe "#initialize" do | ||
| 23 | + it 'take a problem like args' do | ||
| 24 | + problem_destroy.problem.should == problem | ||
| 25 | + end | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + describe "#execute" do | ||
| 29 | + it 'destroy the problem himself' do | ||
| 30 | + problem.should_receive(:delete).and_return(true) | ||
| 31 | + problem_destroy.execute | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + it 'delete all errs associate' do | ||
| 35 | + Err.collection.should_receive(:remove).with(:_id => { '$in' => [err_1.id, err_2.id] }) | ||
| 36 | + problem_destroy.execute | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + it 'delete all comments associate' do | ||
| 40 | + Comment.collection.should_receive(:remove).with(:_id => { '$in' => [comment_1.id, comment_2.id] }) | ||
| 41 | + problem_destroy.execute | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + it 'delete all notice of associate to this errs' do | ||
| 45 | + Notice.collection.should_receive(:remove).with({:err_id => { '$in' => [err_1.id, err_2.id] }}) | ||
| 46 | + problem_destroy.execute | ||
| 47 | + end | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + end | ||
| 51 | + | ||
| 52 | + context "in integration way" do | ||
| 53 | + let!(:problem) { Fabricate(:problem) } | ||
| 54 | + let!(:comment_1) { Fabricate(:comment, :err => problem) } | ||
| 55 | + let!(:comment_2) { Fabricate(:comment, :err => problem) } | ||
| 56 | + let!(:err_1) { Fabricate(:err, :problem => problem) } | ||
| 57 | + let!(:err_2) { Fabricate(:err, :problem => problem) } | ||
| 58 | + let!(:notice_1_1) { Fabricate(:notice, :err => err_1) } | ||
| 59 | + let!(:notice_1_2) { Fabricate(:notice, :err => err_1) } | ||
| 60 | + let!(:notice_2_1) { Fabricate(:notice, :err => err_2) } | ||
| 61 | + let!(:notice_2_2) { Fabricate(:notice, :err => err_2) } | ||
| 62 | + | ||
| 63 | + it 'should all destroy' do | ||
| 64 | + problem_destroy.execute | ||
| 65 | + Problem.where(:_id => problem.id).entries.should be_empty | ||
| 66 | + Err.where(:_id => err_1.id).entries.should be_empty | ||
| 67 | + Err.where(:_id => err_2.id).entries.should be_empty | ||
| 68 | + Comment.where(:_id => comment_1.id).entries.should be_empty | ||
| 69 | + Comment.where(:_id => comment_2.id).entries.should be_empty | ||
| 70 | + Notice.where(:_id => notice_1_1.id).entries.should be_empty | ||
| 71 | + Notice.where(:_id => notice_1_2.id).entries.should be_empty | ||
| 72 | + Notice.where(:_id => notice_2_1.id).entries.should be_empty | ||
| 73 | + Notice.where(:_id => notice_2_2.id).entries.should be_empty | ||
| 74 | + end | ||
| 75 | + end | ||
| 76 | + | ||
| 77 | +end |