Commit Graph

90 Commits

Author SHA1 Message Date
yuuji.yaginuma
21747560be Remove duplicated test
With 8b4d344815655027d9f7584c0a59271dce8f1d5a, `test_required_polymorphic_belongs_to_generates_correct_model`
and `test_required_and_polymorphic_are_order_independent` are completely
same. Also, remove `required` from test name because that not passed to
generator.
2019-04-20 09:30:22 +09:00
Prathamesh Sonpatki
8b4d344815
Add null: false constraint by default for belongs_to associations
- Also deprecate passing {required} to the model generator.
- Also made sure the global config `belongs_to_required_by_default` is
  applied correctly to the model generator for `null: false` option.
2019-04-19 20:08:29 +05:30
Abhay Nikam
cc75e58759 Fix typo in test description from generages -> generates 2019-04-17 22:42:16 +05:30
Prathamesh Sonpatki
76c1528c5f
Remove required: true from the model generator template
`belongs_to` association have `required: true` by default
https://github.com/rails/rails/pull/18937 onwards so we don't need it
in the generator template.
We still need the code for required in the command line generator as
it adds `null: false` in the migration.
2019-04-15 20:27:55 +05:30
Chris Oliver
ecdcf06cb2 Add attachment and attachments field generators 2019-03-30 12:15:17 -05:00
Chris Oliver
19a29c6556 Add rich_text field to model generators 2019-03-28 23:58:33 -05:00
yuuji.yaginuma
e5d7b98fbd Make aliases of database option in generators work
Thor automatically adds `-` if aliases do not start with `-`.
0879c1773d/lib/thor/parser/options.rb (L53)

But Thor follows a convention of one-dash-one-letter options.
So, even if `-` is added to `db`, it does not work.
0879c1773d/lib/thor/parser/options.rb (L4)

Follow up #34021.
2019-03-20 14:52:01 +09:00
alkesh26
79c3cef444 Railities typo fixes. 2019-02-01 16:42:40 +05:30
Gannon McGibbon
4775d3d051 Refactor migrations_path command option to database 2018-09-28 14:24:36 -04:00
Gannon McGibbon
77aaeced89 Add migrations_paths option to model generator 2018-09-27 10:35:52 -04:00
Yoshiyuki Kinjo
ae6adf98cc Emit warning for unknown inflection rule when generating model.
For words like "abuse", Rails cannot derive its singular form from
plural form "abuses" without defining custom inflection rule.
`rails generate model` and its families now emit warning for this case.
2018-08-31 15:47:35 +09:00
Rafael Mendonça França
89bcca59e9 Remove usage of strip_heredoc in the framework in favor of <<~
Some places we can't remove because Ruby still don't have a method
equivalent to strip_heredoc to be called in an already existent string.
2018-02-16 19:28:30 -05:00
Pat Allan
acea68de02 Adding frozen_string_literal pragma to Railties. 2017-08-14 19:08:09 +02:00
Lisa Ugray
75ccdfed8d Stop creating ApplicationRecord on model generation
When generating models, we created ApplicationRecord in the default
location if no file existed there.  That was annoying for people who
moved it to somewhere else in the autoload path.  At this point, the
vast majority of apps should have either run the upgrade script or
generated a model since upgrading.  For those that haven't the error
message after generating a new model should be helpful:

   NameError: uninitialized constant ApplicationRecord

To ease friction in that case, this also adds a generator for
ApplicationRecord.
2017-07-24 21:22:48 -04:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Ryuta Kamizono
b201474756 Should escape meta characters in regexp 2017-05-07 04:10:00 +09:00
Andrew White
33eef3fc28 Move config reset to ensure block
We don't want to leak the extra migration path to other railties tests.
2017-01-17 18:06:59 +00:00
Kevin Glowacz
c942361a60
Generate migrations at path set by config.paths["db/migrate"] 2017-01-16 12:24:37 -06:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
411ccbdab2 remove redundant curlies from hash arguments 2016-08-06 19:44:11 +02:00
Xavier Noria
783763bde9 applies new string literal convention in railties/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:16:09 +02:00
Wojciech Wnętrzak
b991017bf1
Generate application_record.rb file before model file
Previously model file was generated first, which resulted in
inheriting from `ActiveRecord::Base`, but since application_record.rb
is generated as well, it should already be used.
2016-06-08 08:52:12 +02:00
Jon Moss
1813b29fc7 Generate ApplicationRecord if it does not already exist 2016-02-22 20:45:36 -05:00
yuuji.yaginuma
00c64e8ae2 set association name to generated fixtures if attribute is reference
It has been changed to require `belongs_to` by default in Rails 5.
Therefore in order to pass the controller test, have association of set to fixtures.

Fixes #23384
2016-02-06 22:41:10 +09:00
Prathamesh Sonpatki
909818b93b Pare back default index option for the migration generator
- Using `references` or `belongs_to` in migrations will always add index
  for the referenced column by default, without adding `index:true` option
  to generated migration file.
- Users can opt out of this by passing `index: false`.
- Legacy migrations won't be affected by this change. They will continue
  to run as they were before.
- Fixes #18146
2016-01-24 18:48:15 +05:30
Genadi Samokovarov
2067fff9e3 Introduce ApplicationRecord, an Active Record layer supertype
It's pretty common for folks to monkey patch `ActiveRecord::Base` to
work around an issue or introduce extra functionality. Instead of
shoving even more stuff in `ActiveRecord::Base`, `ApplicationRecord` can
hold all those custom work the apps may need.

Now, we don't wanna encourage all of the application models to inherit
from `ActiveRecord::Base`, but we can encourage all the models that do,
to inherit from `ApplicationRecord`.

Newly generated applications have `app/models/application_record.rb`
present by default. The model generators are smart enough to recognize
that newly generated models have to inherit from `ApplicationRecord`,
but only if it's present.
2015-12-16 10:30:09 +01:00
Matthew Draper
dc8d40af58 Ensure generated migrations include a version number 2015-12-15 17:18:09 +10:30
Rafael Mendonça França
ff044c3c3a Use thor class_option to make the primary_key_type option work
Also move the method to the right class
2015-10-23 21:34:07 -02:00
yuuji.yaginuma
71c7c68e2d respect pluralize_table_names when generate fixture file. fixes #19519 2015-03-27 17:30:43 +09:00
robertomiranda
5cca205114 Add Secure Token Generator 2015-01-11 14:42:54 -05:00
Rafael Mendonça França
a939506f29 Change the default null value for timestamps to false 2015-01-04 11:58:43 -03:00
Pablo Olmos de Aguilera Corradini
9405ecdd98 Generated fixtures won't use parent_id when generated with parent:references
Fix #18301
2015-01-02 23:01:24 -03:00
Sean Griffin
a03ea684ef Use the new foreign_key option on references in generators
Changes `rails g model Post user:references` from

    def change
      create_table :posts do |t|
        t.references :user, index: true
      end

      add_foreign_key :posts, :users
    end

to

    def change
      create_table :posts do |t|
        t.references :user, index: true, foreign_key: true
      end
    end

Changes `rails g migration add_user_to_posts user:references` from

    def change
      add_reference :posts, :users, index: true
      add_foreign_key :posts, :users
    end

to

    def change
      add_reference :posts, :users, index: true, foreign_key: true
    end
2014-12-22 13:47:11 -07:00
Derek Prior
323334a775 Generators add foreign keys on references
If you run a generator such as:

```
rails generate model accounts supplier:references
```

The resulting migration will now add the corresponding foreign key
constraint unless the reference was specified to be polymorphic.
2014-11-25 20:22:58 -02:00
Rafael Mendonça França
76883f9237 Merge pull request #16062 from sgrif/sg-required-generators
Add a `required` option to the model generator
2014-08-17 22:57:21 -03:00
Sean Griffin
ea3ba34506 Change the default null value for timestamps
As per discussion, this changes the model generators to specify
`null: false` for timestamp columns. A warning is now emitted if
`timestamps` is called without a `null` option specified, so we can
safely change the behavior when no option is specified in Rails 5.
2014-08-12 14:40:11 -06:00
Sean Griffin
fdfc0fc6c9 Add a required option to the model generator
Syntax was chosen to follow the passing of multiple options to
decimal/numeric types. Curly braces, and allowing any of `,`, `.`, or
`-` to be used as a separator to avoid the need for shell quoting. (I'm
intending to expand this to all columns, but that's another PR.

The `required` option will cause 2 things to change. `required: true`
will be added to the association. `null: false` will be added to the
column in the migration.
2014-08-08 10:29:27 -06:00
Kuldeep Aggarwal
adff19cc3b modify model generator warning message. refs [#174c9f0] 2014-02-27 22:04:01 +05:30
Yves Senn
174c9f0df3 include names in model generator warning message. refs #13515.
This is a follow up to #13515. It includes the name given and
the singularized version in the warning message. This will aide the user
to see wether the detected singular was right or not.
2014-02-24 09:45:24 +01:00
Kuldeep Aggarwal
de8bef9878 Add warning when user tried to create model with pluralize name.
1. Generate model with correct_name.
  2. It will help new users to avoid mistakes when tried to create model with wrong name.
2014-02-23 13:10:41 +05:30
Rafael Mendonça França
899cae25ec Consistent use of single and double quotes 2012-12-26 12:23:39 -03:00
Yves Senn
edae4777ad quote column names in generated fixture files 2012-12-26 16:17:47 +01:00
Rafael Mendonça França
8dac9768b1 Make sure that no extra spaces are created with a non-polymorphic
attributes
2012-12-10 23:16:48 -03:00
Rafael Mendonça França
b05b77be9c Deal with polymorphic attributes correctly in the generators 2012-12-10 00:01:41 -03:00
Rafael Mendonça França
4a487f94b9 Make references and belongs_to attributes to generate the _id column in
fixtures
2012-12-10 00:01:40 -03:00
Robin Dupret
5ad7f8ab41 Use Ruby 1.9 Hash syntax in railties 2012-10-14 18:26:58 +02:00
Mike Moore
2a68f68aea Update test locations
Change the default test locations to avoid confusion around the common
testing terms "unit" and "functional".
Add new rake tasks for the new locations, while maintaining backwards
compatibility with the old rake tasks.

New testing locations are as follows:

    app/models -> test/models (was test/units)
    app/helpers -> test/helpers (was test/units/helpers)
    app/controllers -> test/controllers (was test/functional)
    app/mailers -> test/mailers (was test/functional)
2012-10-09 17:53:56 -06:00