├── .gitignore ├── .rubocop.yml ├── .ruby-style.yml ├── .travis.yml ├── Appraisals ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── Guardfile ├── MIT-LICENSE ├── README.md ├── Rakefile ├── active_waiter.gemspec ├── app ├── assets │ ├── images │ │ └── active_waiter │ │ │ └── .keep │ ├── javascripts │ │ └── active_waiter │ │ │ └── application.js │ └── stylesheets │ │ └── active_waiter │ │ └── application.css ├── controllers │ └── active_waiter │ │ ├── application_controller.rb │ │ └── jobs_controller.rb ├── helpers │ └── active_waiter │ │ └── application_helper.rb └── views │ ├── active_waiter │ └── jobs │ │ ├── _reload.html.erb │ │ ├── error.html.erb │ │ ├── link_to.html.erb │ │ ├── progress.html.erb │ │ └── show.html.erb │ └── layouts │ └── active_waiter │ └── application.html.erb ├── bin └── rails ├── config └── routes.rb ├── gemfiles ├── rails_4.2.gemfile ├── rails_5.0.gemfile └── rails_5.1.gemfile ├── lib ├── active_waiter.rb ├── active_waiter │ ├── configuration.rb │ ├── engine.rb │ ├── enumerable_job.rb │ ├── job.rb │ ├── store.rb │ └── version.rb └── tasks │ └── waiter_tasks.rake └── test ├── active_waiter ├── configuration_test.rb ├── enumerable_job_test.rb └── job_test.rb ├── controllers └── active_waiter │ └── jobs_controller_test.rb ├── dummy ├── README.rdoc ├── Rakefile ├── app │ ├── assets │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ ├── application_controller.rb │ │ └── concerns │ │ │ └── .keep │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .keep │ ├── models │ │ ├── .keep │ │ └── concerns │ │ │ └── .keep │ └── views │ │ └── layouts │ │ └── application.html.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ └── setup ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── routes.rb │ └── secrets.yml ├── lib │ └── assets │ │ └── .keep ├── log │ └── .keep └── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ └── favicon.ico ├── integration └── navigation_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | test/dummy/db/*.sqlite3 5 | test/dummy/db/*.sqlite3-journal 6 | test/dummy/log/*.log 7 | test/dummy/tmp/ 8 | test/dummy/.sass-cache 9 | Gemfile.lock 10 | gemfiles/*.lock 11 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: 2 | - .ruby-style.yml 3 | -------------------------------------------------------------------------------- /.ruby-style.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Include: 3 | - "**/*.rake" 4 | - "**/Gemfile" 5 | - "**/Rakefile" 6 | 7 | RunRailsCops: true 8 | DisplayCopNames: false 9 | StyleGuideCopsOnly: false 10 | Style/AccessModifierIndentation: 11 | Description: Check indentation of private/protected visibility modifiers. 12 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected 13 | Enabled: true 14 | EnforcedStyle: indent 15 | SupportedStyles: 16 | - outdent 17 | - indent 18 | Style/AlignHash: 19 | Description: Align the elements of a hash literal if they span more than one line. 20 | Enabled: true 21 | EnforcedHashRocketStyle: key 22 | EnforcedColonStyle: key 23 | EnforcedLastArgumentHashStyle: always_inspect 24 | SupportedLastArgumentHashStyles: 25 | - always_inspect 26 | - always_ignore 27 | - ignore_implicit 28 | - ignore_explicit 29 | Style/AlignParameters: 30 | Description: Align the parameters of a method call if they span more than one line. 31 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-double-indent 32 | Enabled: true 33 | EnforcedStyle: with_first_parameter 34 | SupportedStyles: 35 | - with_first_parameter 36 | - with_fixed_indentation 37 | Style/AndOr: 38 | Description: Use &&/|| instead of and/or. 39 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-and-or-or 40 | Enabled: true 41 | EnforcedStyle: always 42 | SupportedStyles: 43 | - always 44 | - conditionals 45 | Style/BarePercentLiterals: 46 | Description: Checks if usage of %() or %Q() matches configuration. 47 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand 48 | Enabled: true 49 | EnforcedStyle: bare_percent 50 | SupportedStyles: 51 | - percent_q 52 | - bare_percent 53 | Style/BracesAroundHashParameters: 54 | Description: Enforce braces style around hash parameters. 55 | Enabled: false 56 | EnforcedStyle: no_braces 57 | SupportedStyles: 58 | - braces 59 | - no_braces 60 | - context_dependent 61 | Style/CaseIndentation: 62 | Description: Indentation of when in a case/when/[else/]end. 63 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#indent-when-to-case 64 | Enabled: true 65 | IndentWhenRelativeTo: case 66 | SupportedStyles: 67 | - case 68 | - end 69 | IndentOneStep: false 70 | Style/ClassAndModuleChildren: 71 | Description: Checks style of children classes and modules. 72 | Enabled: false 73 | EnforcedStyle: nested 74 | SupportedStyles: 75 | - nested 76 | - compact 77 | Style/ClassCheck: 78 | Description: Enforces consistent use of `Object#is_a?` or `Object#kind_of?`. 79 | Enabled: true 80 | EnforcedStyle: is_a? 81 | SupportedStyles: 82 | - is_a? 83 | - kind_of? 84 | Style/CollectionMethods: 85 | Description: Preferred collection methods. 86 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size 87 | Enabled: false 88 | PreferredMethods: 89 | collect: map 90 | collect!: map! 91 | inject: reduce 92 | detect: find 93 | find_all: select 94 | find: detect 95 | Style/CommentAnnotation: 96 | Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, 97 | REVIEW). 98 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#annotate-keywords 99 | Enabled: false 100 | Keywords: 101 | - TODO 102 | - FIXME 103 | - OPTIMIZE 104 | - HACK 105 | - REVIEW 106 | Style/DotPosition: 107 | Description: Checks the position of the dot in multi-line method calls. 108 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains 109 | Enabled: true 110 | EnforcedStyle: leading 111 | SupportedStyles: 112 | - leading 113 | - trailing 114 | Style/EmptyLineBetweenDefs: 115 | Description: Use empty lines between defs. 116 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods 117 | Enabled: true 118 | AllowAdjacentOneLineDefs: false 119 | Style/EmptyLinesAroundBlockBody: 120 | Description: Keeps track of empty lines around block bodies. 121 | Enabled: true 122 | EnforcedStyle: no_empty_lines 123 | SupportedStyles: 124 | - empty_lines 125 | - no_empty_lines 126 | Style/EmptyLinesAroundClassBody: 127 | Description: Keeps track of empty lines around class bodies. 128 | Enabled: true 129 | EnforcedStyle: no_empty_lines 130 | SupportedStyles: 131 | - empty_lines 132 | - no_empty_lines 133 | Style/EmptyLinesAroundModuleBody: 134 | Description: Keeps track of empty lines around module bodies. 135 | Enabled: true 136 | EnforcedStyle: no_empty_lines 137 | SupportedStyles: 138 | - empty_lines 139 | - no_empty_lines 140 | Style/Encoding: 141 | Description: Use UTF-8 as the source file encoding. 142 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#utf-8 143 | Enabled: false 144 | EnforcedStyle: always 145 | SupportedStyles: 146 | - when_needed 147 | - always 148 | Style/FileName: 149 | Description: Use snake_case for source file names. 150 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files 151 | Enabled: false 152 | Exclude: [] 153 | Style/FirstParameterIndentation: 154 | Description: Checks the indentation of the first parameter in a method call. 155 | Enabled: true 156 | EnforcedStyle: special_for_inner_method_call_in_parentheses 157 | SupportedStyles: 158 | - consistent 159 | - special_for_inner_method_call 160 | - special_for_inner_method_call_in_parentheses 161 | Style/For: 162 | Description: Checks use of for or each in multiline loops. 163 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-for-loops 164 | Enabled: true 165 | EnforcedStyle: each 166 | SupportedStyles: 167 | - for 168 | - each 169 | Style/FormatString: 170 | Description: Enforce the use of Kernel#sprintf, Kernel#format or String#%. 171 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#sprintf 172 | Enabled: false 173 | EnforcedStyle: format 174 | SupportedStyles: 175 | - format 176 | - sprintf 177 | - percent 178 | Style/GlobalVars: 179 | Description: Do not introduce global variables. 180 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#instance-vars 181 | Enabled: false 182 | AllowedVariables: [] 183 | Style/GuardClause: 184 | Description: Check for conditionals that can be replaced with guard clauses 185 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals 186 | Enabled: false 187 | MinBodyLength: 1 188 | Style/HashSyntax: 189 | Description: 'Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 190 | 1, :b => 2 }.' 191 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-literals 192 | Enabled: false 193 | EnforcedStyle: ruby19 194 | SupportedStyles: 195 | - ruby19 196 | - hash_rockets 197 | Style/IfUnlessModifier: 198 | Description: Favor modifier if/unless usage when you have a single-line body. 199 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier 200 | Enabled: false 201 | MaxLineLength: 80 202 | Style/IndentationWidth: 203 | Description: Use 2 spaces for indentation. 204 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-indentation 205 | Enabled: false 206 | Width: 2 207 | Style/IndentHash: 208 | Description: Checks the indentation of the first key in a hash literal. 209 | Enabled: false 210 | EnforcedStyle: special_inside_parentheses 211 | SupportedStyles: 212 | - special_inside_parentheses 213 | - consistent 214 | Style/LambdaCall: 215 | Description: Use lambda.call(...) instead of lambda.(...). 216 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc-call 217 | Enabled: false 218 | EnforcedStyle: call 219 | SupportedStyles: 220 | - call 221 | - braces 222 | Style/Next: 223 | Description: Use `next` to skip iteration instead of a condition at the end. 224 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals 225 | Enabled: false 226 | EnforcedStyle: skip_modifier_ifs 227 | MinBodyLength: 3 228 | SupportedStyles: 229 | - skip_modifier_ifs 230 | - always 231 | Style/NonNilCheck: 232 | Description: Checks for redundant nil checks. 233 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks 234 | Enabled: true 235 | IncludeSemanticChanges: false 236 | Style/MethodDefParentheses: 237 | Description: Checks if the method definitions have or don't have parentheses. 238 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens 239 | Enabled: true 240 | EnforcedStyle: require_parentheses 241 | SupportedStyles: 242 | - require_parentheses 243 | - require_no_parentheses 244 | Style/MethodName: 245 | Description: Use the configured style when naming methods. 246 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars 247 | Enabled: true 248 | EnforcedStyle: snake_case 249 | SupportedStyles: 250 | - snake_case 251 | - camelCase 252 | Style/MultilineOperationIndentation: 253 | Description: Checks indentation of binary operations that span more than one line. 254 | Enabled: false 255 | EnforcedStyle: indented 256 | SupportedStyles: 257 | - aligned 258 | - indented 259 | Style/NumericLiterals: 260 | Description: Add underscores to large numeric literals to improve their readability. 261 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics 262 | Enabled: false 263 | MinDigits: 5 264 | Style/ParenthesesAroundCondition: 265 | Description: Don't use parentheses around the condition of an if/unless/while. 266 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-parens-if 267 | Enabled: true 268 | AllowSafeAssignment: true 269 | Style/PercentLiteralDelimiters: 270 | Description: Use `%`-literal delimiters consistently 271 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces 272 | Enabled: false 273 | PreferredDelimiters: 274 | "%": "()" 275 | "%i": "()" 276 | "%q": "()" 277 | "%Q": "()" 278 | "%r": "{}" 279 | "%s": "()" 280 | "%w": "()" 281 | "%W": "()" 282 | "%x": "()" 283 | Style/PercentQLiterals: 284 | Description: Checks if uses of %Q/%q match the configured preference. 285 | Enabled: true 286 | EnforcedStyle: lower_case_q 287 | SupportedStyles: 288 | - lower_case_q 289 | - upper_case_q 290 | Style/PredicateName: 291 | Description: Check the names of predicate methods. 292 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark 293 | Enabled: true 294 | NamePrefix: 295 | - is_ 296 | - has_ 297 | - have_ 298 | NamePrefixBlacklist: 299 | - is_ 300 | Style/RaiseArgs: 301 | Description: Checks the arguments passed to raise/fail. 302 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages 303 | Enabled: false 304 | EnforcedStyle: exploded 305 | SupportedStyles: 306 | - compact 307 | - exploded 308 | Style/RedundantReturn: 309 | Description: Don't use return where it's not required. 310 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-explicit-return 311 | Enabled: true 312 | AllowMultipleReturnValues: false 313 | Style/RegexpLiteral: 314 | Description: Use %r for regular expressions matching more than `MaxSlashes` '/' 315 | characters. Use %r only for regular expressions matching more than `MaxSlashes` 316 | '/' character. 317 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-r 318 | Enabled: false 319 | Style/Semicolon: 320 | Description: Don't use semicolons to terminate expressions. 321 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-semicolon 322 | Enabled: false 323 | AllowAsExpressionSeparator: false 324 | Style/SignalException: 325 | Description: Checks for proper usage of fail and raise. 326 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method 327 | Enabled: false 328 | EnforcedStyle: semantic 329 | SupportedStyles: 330 | - only_raise 331 | - only_fail 332 | - semantic 333 | Style/SingleLineBlockParams: 334 | Description: Enforces the names of some block params. 335 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks 336 | Enabled: false 337 | Methods: 338 | - reduce: 339 | - a 340 | - e 341 | - inject: 342 | - a 343 | - e 344 | Style/SingleLineMethods: 345 | Description: Avoid single-line methods. 346 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods 347 | Enabled: false 348 | AllowIfMethodIsEmpty: true 349 | Style/StringLiterals: 350 | Description: Checks if uses of quotes match the configured preference. 351 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals 352 | Enabled: false 353 | EnforcedStyle: double_quotes 354 | SupportedStyles: 355 | - single_quotes 356 | - double_quotes 357 | Style/StringLiteralsInInterpolation: 358 | Description: Checks if uses of quotes inside expressions in interpolated strings 359 | match the configured preference. 360 | Enabled: true 361 | EnforcedStyle: single_quotes 362 | SupportedStyles: 363 | - single_quotes 364 | - double_quotes 365 | Style/SpaceAroundBlockParameters: 366 | Description: Checks the spacing inside and after block parameters pipes. 367 | Enabled: true 368 | EnforcedStyleInsidePipes: no_space 369 | SupportedStyles: 370 | - space 371 | - no_space 372 | Style/SpaceAroundEqualsInParameterDefault: 373 | Description: Checks that the equals signs in parameter default assignments have 374 | or don't have surrounding space depending on configuration. 375 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-around-equals 376 | Enabled: false 377 | EnforcedStyle: space 378 | SupportedStyles: 379 | - space 380 | - no_space 381 | Style/SpaceBeforeBlockBraces: 382 | Description: Checks that the left block brace has or doesn't have space before it. 383 | Enabled: true 384 | EnforcedStyle: space 385 | SupportedStyles: 386 | - space 387 | - no_space 388 | Style/SpaceInsideBlockBraces: 389 | Description: Checks that block braces have or don't have surrounding space. For 390 | blocks taking parameters, checks that the left brace has or doesn't have trailing 391 | space. 392 | Enabled: true 393 | EnforcedStyle: space 394 | SupportedStyles: 395 | - space 396 | - no_space 397 | EnforcedStyleForEmptyBraces: no_space 398 | SpaceBeforeBlockParameters: true 399 | Style/SpaceInsideHashLiteralBraces: 400 | Description: Use spaces inside hash literal braces - or don't. 401 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 402 | Enabled: true 403 | EnforcedStyle: space 404 | EnforcedStyleForEmptyBraces: no_space 405 | SupportedStyles: 406 | - space 407 | - no_space 408 | Style/SymbolProc: 409 | Description: Use symbols as procs instead of blocks when possible. 410 | Enabled: true 411 | IgnoredMethods: 412 | - respond_to 413 | Style/TrailingBlankLines: 414 | Description: Checks trailing blank lines and final newline. 415 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#newline-eof 416 | Enabled: true 417 | EnforcedStyle: final_newline 418 | SupportedStyles: 419 | - final_newline 420 | - final_blank_line 421 | Style/TrailingComma: 422 | Description: Checks for trailing comma in parameter lists and literals. 423 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas 424 | Enabled: false 425 | EnforcedStyleForMultiline: no_comma 426 | SupportedStyles: 427 | - comma 428 | - no_comma 429 | Style/TrivialAccessors: 430 | Description: Prefer attr_* methods to trivial readers/writers. 431 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr_family 432 | Enabled: false 433 | ExactNameMatch: false 434 | AllowPredicates: false 435 | AllowDSLWriters: false 436 | Whitelist: 437 | - to_ary 438 | - to_a 439 | - to_c 440 | - to_enum 441 | - to_h 442 | - to_hash 443 | - to_i 444 | - to_int 445 | - to_io 446 | - to_open 447 | - to_path 448 | - to_proc 449 | - to_r 450 | - to_regexp 451 | - to_str 452 | - to_s 453 | - to_sym 454 | Style/VariableName: 455 | Description: Use the configured style when naming variables. 456 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars 457 | Enabled: true 458 | EnforcedStyle: snake_case 459 | SupportedStyles: 460 | - snake_case 461 | - camelCase 462 | Style/WhileUntilModifier: 463 | Description: Favor modifier while/until usage when you have a single-line body. 464 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier 465 | Enabled: false 466 | MaxLineLength: 80 467 | Style/WordArray: 468 | Description: Use %w or %W for arrays of words. 469 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-w 470 | Enabled: false 471 | MinSize: 0 472 | WordRegex: !ruby/regexp /\A[\p{Word}]+\z/ 473 | Metrics/AbcSize: 474 | Description: A calculated magnitude based on number of assignments, branches, and 475 | conditions. 476 | Enabled: true 477 | Max: 50 478 | Metrics/BlockNesting: 479 | Description: Avoid excessive block nesting 480 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count 481 | Enabled: true 482 | Max: 3 483 | Metrics/ClassLength: 484 | Description: Avoid classes longer than 100 lines of code. 485 | Enabled: false 486 | CountComments: false 487 | Max: 100 488 | Metrics/CyclomaticComplexity: 489 | Description: A complexity metric that is strongly correlated to the number of test 490 | cases needed to validate a method. 491 | Enabled: false 492 | Max: 6 493 | Metrics/LineLength: 494 | Description: Limit lines to 80 characters. 495 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits 496 | Enabled: false 497 | Max: 80 498 | AllowURI: true 499 | URISchemes: 500 | - http 501 | - https 502 | Metrics/MethodLength: 503 | Description: Avoid methods longer than 10 lines of code. 504 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods 505 | Enabled: true 506 | CountComments: true 507 | Max: 40 508 | Exclude: 509 | - "spec/**/*" 510 | Metrics/ParameterLists: 511 | Description: Avoid long parameter lists. 512 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params 513 | Enabled: false 514 | Max: 5 515 | CountKeywordArgs: true 516 | Metrics/PerceivedComplexity: 517 | Description: A complexity metric geared towards measuring complexity for a human 518 | reader. 519 | Enabled: false 520 | Max: 7 521 | Lint/AssignmentInCondition: 522 | Description: Don't use assignment in conditions. 523 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition 524 | Enabled: false 525 | AllowSafeAssignment: true 526 | Lint/EndAlignment: 527 | Description: Align ends correctly. 528 | Enabled: false 529 | AlignWith: keyword 530 | SupportedStyles: 531 | - keyword 532 | - variable 533 | Lint/DefEndAlignment: 534 | Description: Align ends corresponding to defs correctly. 535 | Enabled: true 536 | AlignWith: start_of_line 537 | SupportedStyles: 538 | - start_of_line 539 | - def 540 | Rails/ActionFilter: 541 | Description: Enforces consistent use of action filter methods. 542 | Enabled: true 543 | EnforcedStyle: action 544 | SupportedStyles: 545 | - action 546 | - filter 547 | Include: 548 | - app/controllers/**/*.rb 549 | Rails/DefaultScope: 550 | Description: Checks if the argument passed to default_scope is a block. 551 | Enabled: true 552 | Include: 553 | - app/models/**/*.rb 554 | Rails/HasAndBelongsToMany: 555 | Description: Prefer has_many :through to has_and_belongs_to_many. 556 | Enabled: false 557 | Include: 558 | - app/models/**/*.rb 559 | Rails/Output: 560 | Description: Checks for calls to puts, print, etc. 561 | Enabled: true 562 | Include: 563 | - app/**/*.rb 564 | - config/**/*.rb 565 | - db/**/*.rb 566 | - lib/**/*.rb 567 | Rails/ReadWriteAttribute: 568 | Description: Checks for read_attribute(:attr) and write_attribute(:attr, val). 569 | Enabled: true 570 | Include: 571 | - app/models/**/*.rb 572 | Rails/ScopeArgs: 573 | Description: Checks the arguments of ActiveRecord scopes. 574 | Enabled: true 575 | Include: 576 | - app/models/**/*.rb 577 | Rails/Validation: 578 | Description: Use validates :attribute, hash of validations. 579 | Enabled: false 580 | Include: 581 | - app/models/**/*.rb 582 | Style/InlineComment: 583 | Description: Avoid inline comments. 584 | Enabled: false 585 | Style/MethodCalledOnDoEndBlock: 586 | Description: Avoid chaining a method call on a do...end block. 587 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 588 | Enabled: false 589 | Style/SymbolArray: 590 | Description: Use %i or %I for arrays of symbols. 591 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-i 592 | Enabled: false 593 | Style/ExtraSpacing: 594 | Description: Do not use unnecessary spacing. 595 | Enabled: false 596 | Style/AccessorMethodName: 597 | Description: Check the naming of accessor methods for get_/set_. 598 | Enabled: false 599 | Style/Alias: 600 | Description: Use alias_method instead of alias. 601 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method 602 | Enabled: false 603 | Style/AlignArray: 604 | Description: Align the elements of an array literal if they span more than one line. 605 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays 606 | Enabled: true 607 | Style/ArrayJoin: 608 | Description: Use Array#join instead of Array#*. 609 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#array-join 610 | Enabled: false 611 | Style/AsciiComments: 612 | Description: Use only ascii symbols in comments. 613 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#english-comments 614 | Enabled: false 615 | Style/AsciiIdentifiers: 616 | Description: Use only ascii symbols in identifiers. 617 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#english-identifiers 618 | Enabled: false 619 | Style/Attr: 620 | Description: Checks for uses of Module#attr. 621 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr 622 | Enabled: false 623 | Style/BeginBlock: 624 | Description: Avoid the use of BEGIN blocks. 625 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks 626 | Enabled: true 627 | Style/BlockComments: 628 | Description: Do not use block comments. 629 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-block-comments 630 | Enabled: true 631 | Style/BlockEndNewline: 632 | Description: Put end statement of multiline block on its own line. 633 | Enabled: true 634 | Style/Blocks: 635 | Description: Avoid using {...} for multi-line blocks. 636 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 637 | Enabled: false 638 | Style/CaseEquality: 639 | Description: Avoid explicit use of the case equality operator(===). 640 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-case-equality 641 | Enabled: false 642 | Style/CharacterLiteral: 643 | Description: Checks for uses of character literals. 644 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-character-literals 645 | Enabled: false 646 | Style/ClassAndModuleCamelCase: 647 | Description: Use CamelCase for classes and modules. 648 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#camelcase-classes 649 | Enabled: true 650 | Style/ClassMethods: 651 | Description: Use self when defining module/class methods. 652 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#def-self-singletons 653 | Enabled: true 654 | Style/ClassVars: 655 | Description: Avoid the use of class variables. 656 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-class-vars 657 | Enabled: false 658 | Style/ColonMethodCall: 659 | Description: 'Do not use :: for method call.' 660 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#double-colons 661 | Enabled: false 662 | Style/CommentIndentation: 663 | Description: Indentation of comments. 664 | Enabled: true 665 | Style/ConstantName: 666 | Description: Constants should use SCREAMING_SNAKE_CASE. 667 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#screaming-snake-case 668 | Enabled: true 669 | Style/DefWithParentheses: 670 | Description: Use def with parentheses when there are arguments. 671 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens 672 | Enabled: true 673 | Style/DeprecatedHashMethods: 674 | Description: Checks for use of deprecated Hash methods. 675 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-key 676 | Enabled: false 677 | Style/Documentation: 678 | Description: Document classes and non-namespace modules. 679 | Enabled: false 680 | Style/DoubleNegation: 681 | Description: Checks for uses of double negation (!!). 682 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang 683 | Enabled: false 684 | Style/EachWithObject: 685 | Description: Prefer `each_with_object` over `inject` or `reduce`. 686 | Enabled: false 687 | Style/ElseAlignment: 688 | Description: Align elses and elsifs correctly. 689 | Enabled: false 690 | Style/EmptyElse: 691 | Description: Avoid empty else-clauses. 692 | Enabled: false 693 | Style/EmptyLines: 694 | Description: Don't use several empty lines in a row. 695 | Enabled: true 696 | Style/EmptyLinesAroundAccessModifier: 697 | Description: Keep blank lines around access modifiers. 698 | Enabled: true 699 | Style/EmptyLinesAroundMethodBody: 700 | Description: Keeps track of empty lines around method bodies. 701 | Enabled: true 702 | Style/EmptyLiteral: 703 | Description: Prefer literals to Array.new/Hash.new/String.new. 704 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash 705 | Enabled: false 706 | Style/EndBlock: 707 | Description: Avoid the use of END blocks. 708 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-END-blocks 709 | Enabled: true 710 | Style/EndOfLine: 711 | Description: Use Unix-style line endings. 712 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#crlf 713 | Enabled: true 714 | Style/EvenOdd: 715 | Description: Favor the use of Fixnum#even? && Fixnum#odd? 716 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#predicate-methods 717 | Enabled: false 718 | Style/FlipFlop: 719 | Description: Checks for flip flops 720 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-flip-flops 721 | Enabled: false 722 | Style/IfWithSemicolon: 723 | Description: Do not use if x; .... Use the ternary operator instead. 724 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs 725 | Enabled: false 726 | Style/IndentationConsistency: 727 | Description: Keep indentation straight. 728 | Enabled: false 729 | Style/IndentArray: 730 | Description: Checks the indentation of the first element in an array literal. 731 | Enabled: true 732 | Style/InfiniteLoop: 733 | Description: Use Kernel#loop for infinite loops. 734 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#infinite-loop 735 | Enabled: true 736 | Style/Lambda: 737 | Description: Use the new lambda literal syntax for single-line blocks. 738 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#lambda-multi-line 739 | Enabled: false 740 | Style/LeadingCommentSpace: 741 | Description: Comments should start with a space. 742 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-space 743 | Enabled: true 744 | Style/LineEndConcatenation: 745 | Description: Use \ instead of + or << to concatenate two string literals at line 746 | end. 747 | Enabled: false 748 | Style/MethodCallParentheses: 749 | Description: Do not use parentheses for method calls with no arguments. 750 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-args-no-parens 751 | Enabled: true 752 | Style/ModuleFunction: 753 | Description: Checks for usage of `extend self` in modules. 754 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function 755 | Enabled: false 756 | Style/MultilineBlockChain: 757 | Description: Avoid multi-line chains of blocks. 758 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks 759 | Enabled: true 760 | Style/MultilineBlockLayout: 761 | Description: Ensures newlines after multiline block do statements. 762 | Enabled: true 763 | Style/MultilineIfThen: 764 | Description: Do not use then for multi-line if/unless. 765 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-then 766 | Enabled: true 767 | Style/MultilineTernaryOperator: 768 | Description: 'Avoid multi-line ?: (the ternary operator); use if/unless instead.' 769 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary 770 | Enabled: true 771 | Style/NegatedIf: 772 | Description: Favor unless over if for negative conditions (or control flow or). 773 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#unless-for-negatives 774 | Enabled: false 775 | Style/NegatedWhile: 776 | Description: Favor until over while for negative conditions. 777 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#until-for-negatives 778 | Enabled: false 779 | Style/NestedTernaryOperator: 780 | Description: Use one expression per branch in a ternary operator. 781 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-ternary 782 | Enabled: true 783 | Style/NilComparison: 784 | Description: Prefer x.nil? to x == nil. 785 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#predicate-methods 786 | Enabled: false 787 | Style/Not: 788 | Description: Use ! instead of not. 789 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#bang-not-not 790 | Enabled: false 791 | Style/OneLineConditional: 792 | Description: Favor the ternary operator(?:) over if/then/else/end constructs. 793 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator 794 | Enabled: false 795 | Style/OpMethod: 796 | Description: When defining binary operators, name the argument other. 797 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#other-arg 798 | Enabled: false 799 | Style/PerlBackrefs: 800 | Description: Avoid Perl-style regex back references. 801 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers 802 | Enabled: false 803 | Style/Proc: 804 | Description: Use proc instead of Proc.new. 805 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc 806 | Enabled: false 807 | Style/RedundantBegin: 808 | Description: Don't use begin blocks when they are not needed. 809 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#begin-implicit 810 | Enabled: true 811 | Style/RedundantException: 812 | Description: Checks for an obsolete RuntimeException argument in raise/fail. 813 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror 814 | Enabled: true 815 | Style/RedundantSelf: 816 | Description: Don't use self where it's not needed. 817 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required 818 | Enabled: true 819 | Style/RescueModifier: 820 | Description: Avoid using rescue in its modifier form. 821 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers 822 | Enabled: true 823 | Style/SelfAssignment: 824 | Description: Checks for places where self-assignment shorthand should have been 825 | used. 826 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#self-assignment 827 | Enabled: false 828 | Style/SingleSpaceBeforeFirstArg: 829 | Description: Checks that exactly one space is used between a method name and the 830 | first argument for method calls without parentheses. 831 | Enabled: false 832 | Style/SpaceAfterColon: 833 | Description: Use spaces after colons. 834 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 835 | Enabled: true 836 | Style/SpaceAfterComma: 837 | Description: Use spaces after commas. 838 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 839 | Enabled: true 840 | Style/SpaceAfterControlKeyword: 841 | Description: Use spaces after if/elsif/unless/while/until/case/when. 842 | Enabled: true 843 | Style/SpaceAfterMethodName: 844 | Description: Do not put a space between a method name and the opening parenthesis 845 | in a method definition. 846 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-no-spaces 847 | Enabled: true 848 | Style/SpaceAfterNot: 849 | Description: Tracks redundant space after the ! operator. 850 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-space-bang 851 | Enabled: true 852 | Style/SpaceAfterSemicolon: 853 | Description: Use spaces after semicolons. 854 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 855 | Enabled: true 856 | Style/SpaceBeforeComma: 857 | Description: No spaces before commas. 858 | Enabled: false 859 | Style/SpaceBeforeComment: 860 | Description: Checks for missing space between code and a comment on the same line. 861 | Enabled: true 862 | Style/SpaceBeforeSemicolon: 863 | Description: No spaces before semicolons. 864 | Enabled: true 865 | Style/SpaceAroundOperators: 866 | Description: Use spaces around operators. 867 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators 868 | Enabled: false 869 | Style/SpaceBeforeModifierKeyword: 870 | Description: Put a space before the modifier keyword. 871 | Enabled: true 872 | Style/SpaceInsideBrackets: 873 | Description: No spaces after [ or before ]. 874 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-spaces-braces 875 | Enabled: true 876 | Style/SpaceInsideParens: 877 | Description: No spaces after ( or before ). 878 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-spaces-braces 879 | Enabled: true 880 | Style/SpaceInsideRangeLiteral: 881 | Description: No spaces inside range literals. 882 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals 883 | Enabled: true 884 | Style/SpecialGlobalVars: 885 | Description: Avoid Perl-style global variables. 886 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms 887 | Enabled: false 888 | Style/StructInheritance: 889 | Description: Checks for inheritance from Struct.new. 890 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new 891 | Enabled: true 892 | Style/Tab: 893 | Description: No hard tabs. 894 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-indentation 895 | Enabled: true 896 | Style/TrailingWhitespace: 897 | Description: Avoid trailing whitespace. 898 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace 899 | Enabled: true 900 | Style/UnlessElse: 901 | Description: Do not use unless with else. Rewrite these with the positive case first. 902 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-else-with-unless 903 | Enabled: true 904 | Style/UnneededCapitalW: 905 | Description: Checks for %W when interpolation is not needed. 906 | Enabled: true 907 | Style/UnneededPercentQ: 908 | Description: Checks for %q/%Q when single quotes or double quotes would do. 909 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-q 910 | Enabled: true 911 | Style/VariableInterpolation: 912 | Description: Don't interpolate global, instance and class variables directly in 913 | strings. 914 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate 915 | Enabled: false 916 | Style/WhenThen: 917 | Description: Use when x then ... for one-line cases. 918 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases 919 | Enabled: false 920 | Style/WhileUntilDo: 921 | Description: Checks for redundant do after while or until. 922 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do 923 | Enabled: true 924 | Lint/AmbiguousOperator: 925 | Description: Checks for ambiguous operators in the first argument of a method invocation 926 | without parentheses. 927 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-as-args 928 | Enabled: false 929 | Lint/AmbiguousRegexpLiteral: 930 | Description: Checks for ambiguous regexp literals in the first argument of a method 931 | invocation without parenthesis. 932 | Enabled: false 933 | Lint/BlockAlignment: 934 | Description: Align block ends correctly. 935 | Enabled: true 936 | Lint/ConditionPosition: 937 | Description: Checks for condition placed in a confusing position relative to the 938 | keyword. 939 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#same-line-condition 940 | Enabled: false 941 | Lint/Debugger: 942 | Description: Check for debugger calls. 943 | Enabled: true 944 | Lint/DeprecatedClassMethods: 945 | Description: Check for deprecated class method calls. 946 | Enabled: false 947 | Lint/DuplicateMethods: 948 | Description: Check for duplicate methods calls. 949 | Enabled: true 950 | Lint/ElseLayout: 951 | Description: Check for odd code arrangement in an else block. 952 | Enabled: false 953 | Lint/EmptyEnsure: 954 | Description: Checks for empty ensure block. 955 | Enabled: true 956 | Lint/EmptyInterpolation: 957 | Description: Checks for empty string interpolation. 958 | Enabled: true 959 | Lint/EndInMethod: 960 | Description: END blocks should not be placed inside method definitions. 961 | Enabled: true 962 | Lint/EnsureReturn: 963 | Description: Do not use return in an ensure block. 964 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-return-ensure 965 | Enabled: true 966 | Lint/Eval: 967 | Description: The use of eval represents a serious security risk. 968 | Enabled: true 969 | Lint/HandleExceptions: 970 | Description: Don't suppress exception. 971 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions 972 | Enabled: false 973 | Lint/InvalidCharacterLiteral: 974 | Description: Checks for invalid character literals with a non-escaped whitespace 975 | character. 976 | Enabled: false 977 | Lint/LiteralInCondition: 978 | Description: Checks of literals used in conditions. 979 | Enabled: false 980 | Lint/LiteralInInterpolation: 981 | Description: Checks for literals used in interpolation. 982 | Enabled: false 983 | Lint/Loop: 984 | Description: Use Kernel#loop with break rather than begin/end/until or begin/end/while 985 | for post-loop tests. 986 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#loop-with-break 987 | Enabled: false 988 | Lint/ParenthesesAsGroupedExpression: 989 | Description: Checks for method calls with a space before the opening parenthesis. 990 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#parens-no-spaces 991 | Enabled: false 992 | Lint/RequireParentheses: 993 | Description: Use parentheses in the method call to avoid confusion about precedence. 994 | Enabled: false 995 | Lint/RescueException: 996 | Description: Avoid rescuing the Exception class. 997 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-blind-rescues 998 | Enabled: true 999 | Lint/ShadowingOuterLocalVariable: 1000 | Description: Do not use the same name as outer local variable for block arguments 1001 | or block local variables. 1002 | Enabled: true 1003 | Lint/SpaceBeforeFirstArg: 1004 | Description: Put a space between a method name and the first argument in a method 1005 | call without parentheses. 1006 | Enabled: true 1007 | Lint/StringConversionInInterpolation: 1008 | Description: Checks for Object#to_s usage in string interpolation. 1009 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-to-s 1010 | Enabled: true 1011 | Lint/UnderscorePrefixedVariableName: 1012 | Description: Do not use prefix `_` for a variable that is used. 1013 | Enabled: false 1014 | Lint/UnusedBlockArgument: 1015 | Description: Checks for unused block arguments. 1016 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1017 | Enabled: false 1018 | Lint/UnusedMethodArgument: 1019 | Description: Checks for unused method arguments. 1020 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1021 | Enabled: true 1022 | Lint/UnreachableCode: 1023 | Description: Unreachable code. 1024 | Enabled: true 1025 | Lint/UselessAccessModifier: 1026 | Description: Checks for useless access modifiers. 1027 | Enabled: true 1028 | Lint/UselessAssignment: 1029 | Description: Checks for useless assignment to a local variable. 1030 | StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars 1031 | Enabled: true 1032 | Lint/UselessComparison: 1033 | Description: Checks for comparison of something with itself. 1034 | Enabled: true 1035 | Lint/UselessElseWithoutRescue: 1036 | Description: Checks for useless `else` in `begin..end` without `rescue`. 1037 | Enabled: true 1038 | Lint/UselessSetterCall: 1039 | Description: Checks for useless setter call to a local variable. 1040 | Enabled: true 1041 | Lint/Void: 1042 | Description: Possible use of operator/literal/variable in void context. 1043 | Enabled: false 1044 | Rails/Delegate: 1045 | Description: Prefer delegate method for delegations. 1046 | Enabled: false 1047 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | bundler_args: --retry=3 --jobs=8 --no-deployment 3 | cache: bundler 4 | sudo: false 5 | rvm: 6 | - 2.2.5 7 | - 2.2.6 8 | - 2.3.0 9 | - 2.3.1 10 | - 2.3.2 11 | - 2.3.3 12 | - 2.4.1 13 | - ruby-head 14 | gemfile: 15 | - gemfiles/rails_5.1.gemfile 16 | - gemfiles/rails_5.0.gemfile 17 | - gemfiles/rails_4.2.gemfile 18 | matrix: 19 | allow_failures: 20 | - rvm: ruby-head 21 | fast_finish: true 22 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | [5.1, 5.0, 4.2].each do |version| 2 | appraise "rails-#{version}" do 3 | gem "rails", "~> #{version}.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 0.3.4 4 | 5 | - Support Rails 5.1 6 | 7 | ## 0.3.0 8 | 9 | - Add ActiveWaiter::EnumerableJob as template for jobs that loop through resultset 10 | 11 | ## 0.2.0 - 2015.05.26 12 | 13 | - Support Ruby 2.0+ [PR#10](https://github.com/choonkeat/active_waiter/pull/10) 14 | 15 | - Add configuration option for layout [PR#1](https://github.com/choonkeat/active_waiter/pull/1/) 16 | 17 | ## 0.1.0 - 2015.05.24 18 | 19 | - Add toggle for download or redirect in controller/view [0dc1f1](https://github.com/choonkeat/active_waiter/commit/0dc1f1eea6ec6bb9fc5632ce976855d668ad423a) 20 | 21 | ## 0.0.1 - 2015.05.24 22 | 23 | - active waiter init 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | ### Development 4 | 5 | Run `bundle` to install development dependencies. 6 | 7 | #### Running Tests 8 | 9 | ``` 10 | $ rake 11 | ``` 12 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) 6 | 7 | ## Uncomment to clear the screen before every task 8 | # clearing :on 9 | 10 | ## Guard internally checks for changes in the Guardfile and exits. 11 | ## If you want Guard to automatically start up again, run guard in a 12 | ## shell loop, e.g.: 13 | ## 14 | ## $ while bundle exec guard; do echo "Restarting Guard..."; done 15 | ## 16 | ## Note: if you are using the `directories` clause above and you are not 17 | ## watching the project directory ('.'), then you will want to move 18 | ## the Guardfile to a watched dir and symlink it back, e.g. 19 | # 20 | # $ mkdir config 21 | # $ mv Guardfile config/ 22 | # $ ln -s config/Guardfile . 23 | # 24 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 25 | 26 | guard :minitest do 27 | # with Minitest::Unit 28 | watch(%r{^test/(.*)\/?(.*)_test\.rb$}) 29 | watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" } 30 | watch(%r{^test/test_helper\.rb$}) { 'test' } 31 | 32 | # with Minitest::Spec 33 | # watch(%r{^spec/(.*)_spec\.rb$}) 34 | # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 35 | # watch(%r{^spec/spec_helper\.rb$}) { 'spec' } 36 | 37 | # Rails 4 38 | # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } 39 | # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } 40 | watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" } 41 | # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } 42 | # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } 43 | # watch(%r{^test/.+_test\.rb$}) 44 | # watch(%r{^test/test_helper\.rb$}) { 'test' } 45 | 46 | # Rails < 4 47 | # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } 48 | # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" } 49 | # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } 50 | 51 | callback(:start_begin) { `bundle exec rubocop -DR --auto-correct` } 52 | end 53 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 choonkeat 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ActiveWaiter 2 | 3 | [![Build Status](https://travis-ci.org/choonkeat/active_waiter.svg?branch=master)](https://travis-ci.org/choonkeat/active_waiter) 4 | 5 | A simple mechanism allowing your users to wait for the completion of your `ActiveJob` 6 | 7 | ## Scenario 8 | 9 | You have an export PDF feature that you've implemented directly in the controller action. 10 | 11 | As data grows, your HTTP request takes longer and starts timing out. So you decide to move the PDF generating code into a background job. 12 | 13 | ``` ruby 14 | def index 15 | respond_to do |format| 16 | format.html 17 | format.pdf { 18 | ExportPdfJob.perform_later(@things, current_user) 19 | redirect_to :back, notice: "We'll email your PDF when it's done!" 20 | } 21 | end 22 | end 23 | ``` 24 | 25 | But how do you get that PDF into the hands of your users now? Email? Push notification? Manual reload? 26 | 27 | > You have no PDF ready for download (yet). Please reload. 28 | 29 | 30 | ## Solution 31 | 32 | Let `ActiveWaiter` enqueue that job instead and redirect to its progress tracking page. 33 | 34 | ``` ruby 35 | def index 36 | respond_to do |format| 37 | format.html 38 | format.pdf { 39 | uid = ActiveWaiter.enqueue(ExportPdfJob, @things, current_user) 40 | redirect_to active_waiter_path(id: uid) 41 | } 42 | end 43 | end 44 | ``` 45 | 46 | ``` ruby 47 | # routes.rb 48 | mount ActiveWaiter::Engine => "/active_waiter" 49 | ``` 50 | 51 | When the job completes, the user will be redirected to the `url` returned by the job. However, if you want the user to be presented with a download link, add `download: 1` params instead 52 | 53 | ``` ruby 54 | redirect_to active_waiter_path(id: uid, download: 1) 55 | ``` 56 | 57 | ![active_waiter mov](https://cloud.githubusercontent.com/assets/473/7785141/c4667734-01b4-11e5-8974-3a3b00b3a4b6.gif) 58 | 59 | And we need to add a bit of code into your `ActiveJob` class 60 | 61 | - 1) add `include ActiveWaiter::Job` 62 | - 2) return a `url` from your `perform` method to link to the result page (or file) 63 | 64 | ``` ruby 65 | class ExportPdfJob < ActiveJob::Base 66 | queue_as :default 67 | 68 | # (1) 69 | include ActiveWaiter::Job 70 | 71 | def perform(things, current_user) 72 | count = things.count.to_f 73 | files = [] 74 | things.each_with_index do |thing, index| 75 | files << generate_pdf(thing) 76 | 77 | # (a) 78 | update_active_waiter percentage: (100 * (index+1) / count) 79 | end 80 | 81 | # (2) 82 | upload(combine(files)).s3_url 83 | rescue Exception => e 84 | 85 | # (b) 86 | update_active_waiter error: e.to_s 87 | end 88 | end 89 | ``` 90 | 91 | Optionally, you can also 92 | 93 | - a) report progress while your job runs, using `update_active_waiter(percentage:)` 94 | - b) report if there were any errors, using `update_active_waiter(error:)` 95 | 96 | ### Configuration 97 | 98 | By default, `ActiveWaiter` uses a simple Bootstrap layout. To use your application's layout, configure: 99 | 100 | ```ruby 101 | ActiveWaiter.configure do |config| 102 | config.layout = "layouts/application" 103 | end 104 | ``` 105 | 106 | Next, prefix any routes used in your application's layout with `main_app.`, e.g. `main_app.sign_in_path`. 107 | 108 | This is required because `ActiveWaiter` is a Rails Engine mounted into your application, 109 | and it doesn't know about the routes declared within your application. 110 | 111 | #### Changing the shared cache 112 | 113 | For deploying in production environments, `ActiveWaiter` requires a shared cache to 114 | track the status of downloads. By default it uses the Rails cache. If you want to 115 | use something else other than the Rails cache like redis for example, you may specify 116 | your own implementation: 117 | 118 | ```ruby 119 | class RedisStore 120 | def write(uid, value) 121 | $redis.set("active_waiter:#{uid}", value) 122 | end 123 | 124 | def read(uid) 125 | $redis.get("active_waiter:#{uid}") 126 | end 127 | end 128 | 129 | ActiveWaiter.configure do |config| 130 | config.store = RedisStore.new 131 | end 132 | ``` 133 | 134 | #### Exceptions 135 | 136 | When your job gets an exception, the error message will be written in the error message and passed along 137 | to the user. If your job has a method `suppress_exceptions` that returns a truthy value (default false), 138 | `ActiveWaiter::Job` will swallow the exception and not raise it - this means there will be no retry by 139 | `ActiveJob`. 140 | 141 | ### Common Jobs 142 | 143 | #### ActiveWaiter::EnumerableJob 144 | 145 | If you need to wait, you're likely doing one thing slowly or many things. For the latter case, you can just 146 | `include ActiveWaiter::EnumerableJob` and add a few interface methods 147 | 148 | ``` ruby 149 | def before(*args); end # called once with arguments of `perform` 150 | def enumerable; [] end # an Enumerable interface 151 | def items_count; 1 end # called 0-n times, depending on enumerable 152 | def foreach(item); end # called 0-n times, depending on enumerable 153 | def after; end # called once 154 | def result; end # called once 155 | ``` 156 | 157 | Here's an example from our test code, that will generate an array of range `0...count` and return the sum 158 | of all the numbers 159 | 160 | ``` ruby 161 | class LoopJob < ActiveJob::Base 162 | include ActiveWaiter::EnumerableJob 163 | 164 | attr_accessor :items_count, :enumerable, :result 165 | 166 | def before(count) 167 | @items_count = count 168 | @enumerable = count.times 169 | @result = 0 170 | end 171 | 172 | def foreach(item) 173 | @result += item 174 | end 175 | end 176 | ``` 177 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "rubygems" 3 | require "bundler/setup" 4 | require "bundler/gem_tasks" 5 | require "rake/testtask" 6 | 7 | Rake::TestTask.new do |t| 8 | t.libs << "test" 9 | t.test_files = FileList['test/**/*_test.rb'] 10 | t.verbose = true 11 | end 12 | 13 | task default: :test 14 | -------------------------------------------------------------------------------- /active_waiter.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "active_waiter/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "active_waiter" 9 | s.version = ActiveWaiter::VERSION 10 | s.authors = ["choonkeat"] 11 | s.email = ["choonkeat@gmail.com"] 12 | s.homepage = "https://github.com/choonkeat/active_waiter" 13 | s.summary = "ActiveWaiter for background jobs to finish" 14 | s.description = "A simple mechanism allowing your users to wait for the completion of your `ActiveJob`" 15 | s.license = "MIT" 16 | 17 | s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 18 | 19 | s.required_ruby_version = "~> 2.0" 20 | 21 | s.add_dependency "rails", ">= 4.2" 22 | 23 | s.add_development_dependency "guard" 24 | s.add_development_dependency "guard-minitest" 25 | s.add_development_dependency "rubocop" 26 | s.add_development_dependency "rails-controller-testing" 27 | s.add_development_dependency "appraisal" 28 | end 29 | -------------------------------------------------------------------------------- /app/assets/images/active_waiter/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/app/assets/images/active_waiter/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/active_waiter/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require_tree . 14 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_waiter/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/controllers/active_waiter/application_controller.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | class ApplicationController < ActionController::Base 3 | layout :active_waiter_layout 4 | 5 | private 6 | 7 | def active_waiter_layout 8 | ActiveWaiter.configuration.layout 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/active_waiter/jobs_controller.rb: -------------------------------------------------------------------------------- 1 | require_dependency "active_waiter/application_controller" 2 | 3 | module ActiveWaiter 4 | class JobsController < ApplicationController 5 | def show 6 | @retries = nil 7 | data = ActiveWaiter.read(params[:id]) 8 | return on_not_found(data) unless data.respond_to?(:[]) 9 | return on_error(data) if data[:error] 10 | return on_link_to(data) if data[:link_to] && params[:download] 11 | return on_redirect(data) if data[:link_to] 12 | return on_progress(data) if data[:percentage] 13 | end 14 | 15 | protected 16 | 17 | def on_not_found(_data) 18 | case retries = params[:retries].to_i 19 | when 0..9 20 | @retries = retries + 1 21 | else 22 | raise ActionController::RoutingError.new('Not Found') 23 | end 24 | end 25 | 26 | def on_error(data) 27 | render template: "active_waiter/jobs/error", status: :internal_server_error, locals: data 28 | end 29 | 30 | def on_redirect(data) 31 | redirect_to data[:link_to] 32 | end 33 | 34 | def on_link_to(data) 35 | render template: "active_waiter/jobs/link_to", locals: data 36 | end 37 | 38 | def on_progress(data) 39 | render template: "active_waiter/jobs/progress", locals: data 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /app/helpers/active_waiter/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | module ApplicationHelper 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/_reload.html.erb: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/error.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | <%= error %> 5 |
6 |
7 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/link_to.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 100% Complete 4 |
5 |
6 |

7 | 8 | Click to 9 | Download 10 | 11 | 12 |

13 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/progress.html.erb: -------------------------------------------------------------------------------- 1 |

2 |
3 | <%= number_to_percentage(percentage, precision: 1, strip_insignificant_zeros: true) %> Complete 4 |
5 |
6 | <%= render partial: 'reload' %> 7 | -------------------------------------------------------------------------------- /app/views/active_waiter/jobs/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | Please wait… 4 |
5 |
6 | <%= render partial: 'reload' %> 7 | -------------------------------------------------------------------------------- /app/views/layouts/active_waiter/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ActiveWaiter 5 | <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css", media: "all" %> 6 | <%= stylesheet_link_tag "active_waiter/application", media: "all" %> 7 | <%= javascript_include_tag "active_waiter/application" %> 8 | <%= csrf_meta_tags %> 9 | 10 | 11 |
12 |
13 |
14 |
15 |
16 |

17 |

18 | <%= yield %> 19 |
20 |
21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. 3 | 4 | ENGINE_ROOT = File.expand_path('../..', __FILE__) 5 | ENGINE_PATH = File.expand_path('../../lib/active_waiter/engine', __FILE__) 6 | 7 | # Set up gems listed in the Gemfile. 8 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 9 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 10 | 11 | require 'rails/all' 12 | require 'rails/engine/commands' 13 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | ActiveWaiter::Engine.routes.draw do 2 | get '/:id' => 'jobs#show' 3 | root to: 'jobs#show' 4 | end 5 | -------------------------------------------------------------------------------- /gemfiles/rails_4.2.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 4.2.0" 6 | 7 | gemspec path: "../" 8 | -------------------------------------------------------------------------------- /gemfiles/rails_5.0.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 5.0.0" 6 | 7 | gemspec path: "../" 8 | -------------------------------------------------------------------------------- /gemfiles/rails_5.1.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 5.1.0" 6 | 7 | gemspec path: "../" 8 | -------------------------------------------------------------------------------- /lib/active_waiter.rb: -------------------------------------------------------------------------------- 1 | require "active_waiter/engine" 2 | require "active_waiter/store" 3 | require "active_waiter/configuration" 4 | require "active_waiter/job" 5 | require "active_waiter/enumerable_job" 6 | 7 | module ActiveWaiter 8 | class << self 9 | def next_uuid 10 | SecureRandom.uuid 11 | end 12 | 13 | def enqueue(klass, *arguments) 14 | next_uuid.tap do |uid| 15 | ActiveWaiter.write(uid, {}) 16 | klass.perform_later({ uid: uid }, *arguments) 17 | end 18 | end 19 | 20 | def write(uid, value) 21 | ActiveWaiter.configuration.store.write(uid, value) 22 | end 23 | 24 | def read(uid) 25 | ActiveWaiter.configuration.store.read(uid) 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/active_waiter/configuration.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | class << self 3 | attr_writer :configuration 4 | 5 | def configuration 6 | @configuration ||= Configuration.new 7 | end 8 | 9 | def configure 10 | yield configuration 11 | end 12 | end 13 | 14 | class Configuration 15 | attr_accessor :layout, :store 16 | 17 | def initialize 18 | @store = ActiveWaiter::Store.new 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/active_waiter/engine.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | class Engine < ::Rails::Engine 3 | isolate_namespace ActiveWaiter 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/active_waiter/enumerable_job.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter::EnumerableJob 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | include ActiveWaiter::Job 6 | end 7 | 8 | def perform(*args) 9 | before(*args) 10 | enumerable.each_with_index do |item, index| 11 | foreach(item) 12 | update_active_waiter(percentage: (100 * (index+1.to_f) / items_count)) 13 | end 14 | after 15 | result 16 | end 17 | 18 | def before(*_args); end # called once with arguments of `perform` 19 | 20 | def enumerable; [] end # an Enumerable interface 21 | 22 | def items_count; 1 end # called 0-n times, depending on enumerable 23 | 24 | def foreach(_item); end # called 0-n times, depending on enumerable 25 | 26 | def after; end # called once 27 | 28 | def result; end # called once 29 | end 30 | -------------------------------------------------------------------------------- /lib/active_waiter/job.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter::Job 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | around_perform do |job, block| 6 | @active_waiter_options = job.arguments.shift 7 | begin 8 | ::ActiveWaiter.write(@active_waiter_options[:uid], { 9 | percentage: 100, 10 | link_to: block.call, 11 | }) 12 | rescue Exception 13 | ::ActiveWaiter.write(@active_waiter_options[:uid], { 14 | error: $!.to_s, 15 | }) 16 | raise unless suppress_exceptions 17 | end 18 | end 19 | end 20 | 21 | def update_active_waiter(percentage: nil, error: nil) 22 | ::ActiveWaiter.write(@active_waiter_options[:uid], { 23 | percentage: percentage && [percentage, 99].min, 24 | error: error, 25 | }) if @active_waiter_options.try(:[], :uid) 26 | end 27 | 28 | def suppress_exceptions; false; end 29 | end 30 | -------------------------------------------------------------------------------- /lib/active_waiter/store.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | class Store 3 | def write(uid, value) 4 | Rails.cache.write("active_waiter:#{uid}", value) 5 | end 6 | 7 | def read(uid) 8 | Rails.cache.read("active_waiter:#{uid}") 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/active_waiter/version.rb: -------------------------------------------------------------------------------- 1 | module ActiveWaiter 2 | VERSION = "0.3.4" 3 | end 4 | -------------------------------------------------------------------------------- /lib/tasks/waiter_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :active_waiter do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /test/active_waiter/configuration_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TestStore 4 | def initialize 5 | @test_hash = {} 6 | end 7 | 8 | def write(uid, value) 9 | @test_hash[uid] = value 10 | end 11 | 12 | def read(uid) 13 | @test_hash[uid] 14 | end 15 | end 16 | 17 | class ConfigurationTest < Minitest::Test 18 | def test_configuration_defaults 19 | assert_nil ActiveWaiter.configuration.layout 20 | end 21 | 22 | def test_configuration_layout 23 | ActiveWaiter.configure do |config| 24 | config.layout = 'layouts/application' 25 | end 26 | 27 | assert_equal "layouts/application", ActiveWaiter.configuration.layout 28 | ensure 29 | ActiveWaiter.configuration = nil 30 | end 31 | 32 | def test_configuration_store 33 | test_store = TestStore.new 34 | ActiveWaiter.configure do |config| 35 | config.store = test_store 36 | end 37 | 38 | ActiveWaiter.write("abcdef", "test") 39 | assert_equal "test", test_store.read("abcdef") 40 | ensure 41 | ActiveWaiter.configuration = nil 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /test/active_waiter/enumerable_job_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LoopJob < ActiveJob::Base 4 | include ActiveWaiter::EnumerableJob 5 | 6 | attr_accessor :enumerable, :items_count, :suppress_exceptions 7 | 8 | def before(count, suppress: false) 9 | @suppress_exceptions = suppress 10 | @items_count = count 11 | @enumerable = count.times 12 | @result = ["before"] 13 | end 14 | 15 | def foreach(item) 16 | @result.push(item * 2) 17 | end 18 | 19 | def after 20 | @result.push "after" 21 | end 22 | 23 | def result 24 | @result 25 | end 26 | end 27 | 28 | class ActiveWaiter::EnumerableJobTest < Minitest::Test 29 | include ActiveJob::TestHelper 30 | 31 | def test_enumerate_with_progress 32 | ActiveWaiter.stub :next_uuid, uid = "hello" do 33 | expected_progress = [ 34 | [uid, {}], 35 | [uid, { percentage: 20.0, error: nil }], 36 | [uid, { percentage: 40.0, error: nil }], 37 | [uid, { percentage: 60.0, error: nil }], 38 | [uid, { percentage: 80.0, error: nil }], 39 | [uid, { percentage: 99, error: nil }], # last foreach, should be `100` but ActiveWaiter::Job allows max `99` 40 | [uid, { percentage: 100, link_to: ["before", 0, 2, 4, 6, 8, "after"] }], # `100` reported by ActiveWaiter::Job#around_perform 41 | ] 42 | validates_each_write = proc { |*args| assert_equal expected_progress.shift, args; } 43 | ActiveWaiter.stub :write, validates_each_write do |*args| 44 | perform_enqueued_jobs do 45 | assert_equal uid, ActiveWaiter.enqueue(LoopJob, 5) 46 | end 47 | end 48 | end 49 | end 50 | 51 | def test_error 52 | ActiveWaiter.stub :next_uuid, uid = "hello" do 53 | perform_enqueued_jobs do 54 | assert_raises NoMethodError do 55 | assert_equal uid, ActiveWaiter.enqueue(LoopJob, nil, suppress: false) 56 | end 57 | assert_equal Hash(error: "undefined method `times' for nil:NilClass"), ActiveWaiter.read(uid) 58 | end 59 | end 60 | end 61 | 62 | def test_suppressed_error 63 | ActiveWaiter.stub :next_uuid, uid = "hello" do 64 | perform_enqueued_jobs do 65 | assert_equal uid, ActiveWaiter.enqueue(LoopJob, nil, suppress: true) 66 | assert_equal Hash(error: "undefined method `times' for nil:NilClass"), ActiveWaiter.read(uid) 67 | end 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /test/active_waiter/job_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DummyJob < ActiveJob::Base 4 | include ActiveWaiter::Job 5 | 6 | def perform(one, two, three: 3, four: [1, 2, 3, 4]) 7 | [one, two, three, four].to_json 8 | end 9 | end 10 | 11 | class ActiveWaiter::JobTest < Minitest::Test 12 | include ActiveJob::TestHelper 13 | 14 | def teardown 15 | clear_enqueued_jobs 16 | end 17 | 18 | def test_normal 19 | assert_equal expected_return_value, DummyJob.new.perform(*arguments) 20 | end 21 | 22 | def test_active_waiter_enqueue 23 | ActiveWaiter.stub :next_uuid, uid = "hello" do 24 | perform_enqueued_jobs do 25 | assert_equal uid, ActiveWaiter.enqueue(DummyJob, *arguments) 26 | assert_equal Hash(percentage: 100, link_to: expected_return_value), ActiveWaiter.read(uid) 27 | end 28 | end 29 | end 30 | 31 | private 32 | 33 | def arguments 34 | ['a', 'b', four: ['a', 'b', 'c']] 35 | end 36 | 37 | def expected_return_value 38 | ['a', 'b', 3, ['a', 'b', 'c']].to_json 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /test/controllers/active_waiter/jobs_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require 'minitest/mock' 3 | 4 | class RedirectJob < ActiveJob::Base 5 | include ActiveWaiter::Job 6 | 7 | def perform 8 | "http://other.com/12345" 9 | end 10 | end 11 | 12 | class ActiveWaiter::JobsControllerTest < ActionDispatch::IntegrationTest 13 | include ActiveJob::TestHelper 14 | 15 | def setup 16 | @routes = ActiveWaiter::Engine.routes 17 | end 18 | 19 | def teardown 20 | clear_enqueued_jobs 21 | end 22 | 23 | def test_show_non_existent 24 | do_request id: "nosuchjob", download: 0 25 | assert_equal 200, status 26 | assert_match "/active_waiter/nosuchjob?download=0&retries=1".to_json, response.body 27 | end 28 | 29 | def test_show_non_existent_retries_9 30 | do_request id: "nosuchjob", download: 1, retries: "9" 31 | assert_equal 200, status 32 | assert_match "/active_waiter/nosuchjob?download=1&retries=10".to_json, response.body 33 | end 34 | 35 | def test_show_non_existent_retries_10 36 | assert_raises ActionController::RoutingError do 37 | do_request id: "nosuchjob", download: 2, retries: "10" 38 | end 39 | end 40 | 41 | def test_show_started 42 | ActiveWaiter.stub :next_uuid, uid do 43 | assert_equal uid, ActiveWaiter.enqueue(RedirectJob) 44 | do_request id: uid, retries: "9" 45 | assert_equal 200, status 46 | assert_match "Please wait", document_root_element.to_s 47 | assert_match "/active_waiter/#{uid}".to_json, response.body 48 | end 49 | end 50 | 51 | def test_show_error 52 | ActiveWaiter.write(uid, error: "oops") 53 | do_request id: uid 54 | assert_equal 500, status 55 | assert_match "oops", document_root_element.to_s 56 | end 57 | 58 | def test_show_progress 59 | ActiveWaiter.write(uid, percentage: 42) 60 | do_request id: uid, retries: "9" 61 | assert_equal 200, status 62 | assert_match "42%", document_root_element.to_s 63 | assert_match "/active_waiter/#{uid}".to_json, response.body 64 | end 65 | 66 | def test_show_completed_download 67 | ActiveWaiter.stub :next_uuid, uid do 68 | perform_enqueued_jobs do 69 | assert_equal uid, ActiveWaiter.enqueue(RedirectJob) 70 | do_request id: uid, download: 1 71 | assert_equal 200, status 72 | link = document_root_element.css("a[href='http://other.com/12345']").first 73 | assert link, "missing hyperlink to returned value" 74 | assert_match "Click", link.text 75 | end 76 | end 77 | end 78 | 79 | def test_show_completed_redirect 80 | ActiveWaiter.stub :next_uuid, uid do 81 | perform_enqueued_jobs do 82 | assert_equal uid, ActiveWaiter.enqueue(RedirectJob) 83 | do_request id: uid 84 | assert_equal 302, status 85 | assert_equal "http://other.com/12345", response.location 86 | end 87 | end 88 | end 89 | 90 | def test_configuration_layout 91 | ActiveWaiter.configure do |config| 92 | config.layout = 'layouts/application' 93 | end 94 | 95 | ActiveWaiter.stub :next_uuid, uid do 96 | assert_equal uid, ActiveWaiter.enqueue(RedirectJob) 97 | do_request id: uid 98 | assert_template layout: "layouts/application" 99 | end 100 | ensure 101 | ActiveWaiter.configuration = nil 102 | end 103 | 104 | private 105 | 106 | def do_request(params) 107 | if Rails::VERSION::MAJOR < 5 108 | get '/active_waiter', params 109 | else 110 | get '/active_waiter', params: params 111 | end 112 | end 113 | 114 | def uid 115 | "hello" 116 | end 117 | end 118 | -------------------------------------------------------------------------------- /test/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require_tree . 14 | -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/app/mailers/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/app/models/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "action_controller/railtie" 4 | require "action_mailer/railtie" 5 | require "sprockets/railtie" 6 | require "rails/test_unit/railtie" 7 | 8 | Bundler.require(*Rails.groups) 9 | require "active_waiter" 10 | 11 | module Dummy 12 | class Application < Rails::Application 13 | # Settings in config/environments/* take precedence over those specified here. 14 | # Application configuration should go into files in config/initializers 15 | # -- all .rb files in that directory are automatically loaded. 16 | 17 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 18 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 19 | # config.time_zone = 'Central Time (US & Canada)' 20 | 21 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 22 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 23 | # config.i18n.default_locale = :de 24 | 25 | # Do not swallow errors in after_commit/after_rollback callbacks. 26 | # config.active_record.raise_in_transactional_callbacks = true 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | # config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | # config.serve_static_files = true 17 | # config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed. 35 | config.active_support.test_order = :random 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | 43 | config.active_job.queue_adapter = :test 44 | end 45 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | mount ActiveWaiter::Engine => "/active_waiter" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 8ff378f82f0c556b49f961af06d213f042ca7e99546c616867b871f33412b0635a18521af0a5a8d60a61140144479cb4525361f3b4e6ee5a91ba1dfa7e8bba95 15 | 16 | test: 17 | secret_key_base: 998c6716e2a8476305ffe0fcf61ac84eb18db58302586b600412c0bb13b0fb79b0044e3b3dbac634c788fb2eb8e9f60e5460c4850347640b1b8cb86a6323def0 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/log/.keep -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/choonkeat/active_waiter/5d6c82173eff6fcf2bd8bd1c28c6539b9989c2d1/test/dummy/public/favicon.ico -------------------------------------------------------------------------------- /test/integration/navigation_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NavigationTest < ActionDispatch::IntegrationTest 4 | # fixtures :all 5 | 6 | # test "the truth" do 7 | # assert true 8 | # end 9 | end 10 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) 5 | # ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] 6 | # ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) 7 | require "rails/test_help" 8 | 9 | if Rails::VERSION::MAJOR >= 5 10 | require "rails-controller-testing" 11 | Rails::Controller::Testing.install 12 | end 13 | 14 | # Filter out Minitest backtrace while allowing backtrace from other libraries 15 | # to be shown. 16 | Minitest.backtrace_filter = Minitest::BacktraceFilter.new 17 | 18 | # Load support files 19 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 20 | 21 | # Load fixtures from the engine 22 | if ActiveSupport::TestCase.respond_to?(:fixture_path=) 23 | ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) 24 | ActiveSupport::TestCase.fixtures :all 25 | end 26 | --------------------------------------------------------------------------------