anchormodel 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +206 -0
  6. data/README.md +10 -5
  7. data/Rakefile +23 -3
  8. data/anchormodel.gemspec +26 -10
  9. data/doc/Anchormodel/ActiveModelTypeValue.html +10 -6
  10. data/doc/Anchormodel/Attribute.html +21 -14
  11. data/doc/Anchormodel/ModelMixin.html +14 -9
  12. data/doc/Anchormodel/Version.html +3 -3
  13. data/doc/Anchormodel.html +141 -53
  14. data/doc/_index.html +2 -2
  15. data/doc/file.README.html +37 -48
  16. data/doc/index.html +37 -48
  17. data/doc/method_list.html +8 -0
  18. data/doc/top-level-namespace.html +2 -2
  19. data/lib/anchormodel/attribute.rb +2 -2
  20. data/lib/anchormodel/model_mixin.rb +1 -1
  21. data/lib/anchormodel/version.rb +2 -2
  22. data/lib/anchormodel.rb +2 -2
  23. data/logo.svg +98 -0
  24. data/test/active_record_model/user_test.rb +51 -0
  25. data/test/dummy/.gitignore +29 -0
  26. data/test/dummy/Rakefile +6 -0
  27. data/test/dummy/app/anchormodels/locale.rb +6 -0
  28. data/test/dummy/app/anchormodels/role.rb +14 -0
  29. data/test/dummy/app/helpers/application_helper.rb +2 -0
  30. data/test/dummy/app/models/application_record.rb +5 -0
  31. data/test/dummy/app/models/concerns/.keep +0 -0
  32. data/test/dummy/app/models/user.rb +4 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/bin/setup +33 -0
  36. data/test/dummy/config/application.rb +37 -0
  37. data/test/dummy/config/boot.rb +3 -0
  38. data/test/dummy/config/credentials.yml.enc +1 -0
  39. data/test/dummy/config/database.yml +8 -0
  40. data/test/dummy/config/environment.rb +5 -0
  41. data/test/dummy/config/environments/test.rb +50 -0
  42. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  43. data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  44. data/test/dummy/config/initializers/inflections.rb +16 -0
  45. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  46. data/test/dummy/config/locales/en.yml +33 -0
  47. data/test/dummy/config/puma.rb +43 -0
  48. data/test/dummy/config/routes.rb +6 -0
  49. data/test/dummy/config.ru +6 -0
  50. data/test/dummy/db/migrate/20230107173151_create_users.rb +10 -0
  51. data/test/dummy/db/schema.rb +21 -0
  52. data/test/dummy/db/seeds.rb +7 -0
  53. data/test/dummy/lib/tasks/.keep +0 -0
  54. data/test/dummy/log/.keep +0 -0
  55. data/test/dummy/tmp/.keep +0 -0
  56. data/test/dummy/tmp/pids/.keep +0 -0
  57. data/test/test_helper.rb +21 -0
  58. metadata +148 -13
  59. data/anchormodel-0.0.1.gem +0 -0
data/doc/index.html CHANGED
@@ -57,63 +57,52 @@
57
57
  <div class="clear"></div>
58
58
  </div>
59
59
 
60
- <div id="content"><div id='filecontents'><h1 id="introducing-anchormodel">Introducing Anchormodel</h1>
60
+ <div id="content"><div id='filecontents'>
61
+ <p>&lt;img src=“logo.svg” height=250 alt=“Anchormodel logo”/&gt;</p>
61
62
 
62
- <p>This gem provides a simple but powerful alternative to <a href="https://api.rubyonrails.org/v7.0/classes/ActiveRecord/Enum.html">Rails
63
- Enums</a>. In
64
- contrast to regular Enums, Anchormodels can hold application logic, making them
65
- ideal for tying code to database objects.</p>
63
+ <h1 id="label-Introducing+Anchormodel">Introducing Anchormodel</h1>
66
64
 
67
- <h1 id="use-case">Use case</h1>
65
+ <p>This gem provides a simple but powerful alternative to <a href="https://api.rubyonrails.org/v7.0/classes/ActiveRecord/Enum.html">Rails Enums</a>. In contrast to regular Enums, Anchormodels can hold application logic, making them ideal for tying code to database objects.</p>
68
66
 
69
- <p>Typically, a Rails application consists of three kinds of state:</p>
67
+ <h1 id="label-Use+case">Use case</h1>
70
68
 
71
- <ul>
72
- <li>The code, which we can consider static within a given version. Code can
73
- reference to other code, e.g. <code>node.parent = other_node</code>.</li>
74
- <li>The database contents, which can fluctuate within the bounds of the DB schema.
75
- Data can reference to other data, ideally via foreign keys.</li>
76
- <li>A mix of the two, where code needs to be specifically tailored for some kind
77
- of data. A prominent example of such a mix would for instance be user roles:
78
- roles must be hardcoded in the code because security logic is tied to them.
79
- However, as users are assigned to roles in the database, roles also need to be
80
- persisted in the database. This is where Anchormodel comes into play.</li>
81
- </ul>
69
+ <p>Typically, a Rails application consists of three kinds of state:</p>
70
+ <ul><li>
71
+ <p>The code, which we can consider static within a given version. Code can reference to other code, e.g. <code>node.parent = other_node</code>.</p>
72
+ </li><li>
73
+ <p>The database contents, which can fluctuate within the bounds of the DB schema. Data can reference to other data, ideally via foreign keys.</p>
74
+ </li><li>
75
+ <p>A mix of the two, where code needs to be specifically tailored for some kind of data. A prominent example of such a mix would for instance be user roles: roles must be hardcoded in the code because security logic is tied to them. However, as users are assigned to roles in the database, roles also need to be persisted in the database. This is where Anchormodel comes into play.</p>
76
+ </li></ul>
82
77
 
83
- <h2 id="alternatives-coviering-the-same-use-case">Alternatives coviering the same use case</h2>
78
+ <h2 id="label-Alternatives+coviering+the+same+use+case">Alternatives coviering the same use case</h2>
84
79
 
85
- <h3 id="enum">Enum</h3>
80
+ <h3 id="label-Enum">Enum</h3>
86
81
 
87
- <p>In Rails and other frameworks, the third point in the listing above is typically
88
- achieved via Enums. Enums map either Integers or Strings to constants and
89
- therefore provide a link between the DB and the application code.</p>
82
+ <p>In Rails and other frameworks, the third point in the listing above is typically achieved via Enums. Enums map either Integers or Strings to constants and therefore provide a link between the DB and the application code.</p>
90
83
 
91
- <p>However, at least in Rails, Enums provide very limited customization options.
92
- They are basic values that can be used in if-statements. Anchormodels however
93
- are regular classes and can easily be extended.</p>
84
+ <p>However, at least in Rails, Enums provide very limited customization options. They are basic values that can be used in if-statements. Anchormodels however are regular classes and can easily be extended.</p>
94
85
 
95
- <h3 id="activeenum">ActiveEnum</h3>
86
+ <h3 id="label-ActiveEnum">ActiveEnum</h3>
96
87
 
97
- <p>The gem (ActiveEnum)[<a href="https://github.com/adzap/active_enum">https://github.com/adzap/active_enum</a>] allows to create
98
- Enum-like classes that can be extended. However it only supports Integer keys. I
99
- find this unsatisfactory, as debugging with tools like <code>psql</code> or <code>mysql</code> is made
100
- unnecessarily hard when you only see numbers. Keys for enums should be
101
- meaningful, making you immediately understand what they stand for.</p>
88
+ <p>The gem (<a href="https://github.com/adzap/active_enum">ActiveEnum)</a> allows to create Enum-like classes that can be extended. However it only supports Integer keys. I find this unsatisfactory, as debugging with tools like <code>psql</code> or <code>mysql</code> is made unnecessarily hard when you only see numbers. Keys for enums should be meaningful, making you immediately understand what they stand for.</p>
102
89
 
103
- <p>This is why Anchormodel is strictly relying on String keys corresponding to the
104
- entries of an Anchormodel.</p>
90
+ <p>This is why Anchormodel is strictly relying on String keys corresponding to the entries of an Anchormodel.</p>
105
91
 
106
- <h1 id="example">Example</h1>
92
+ <h1 id="label-Example">Example</h1>
107
93
 
108
94
  <p><code>app/anchormodels/role.rb</code>:</p>
109
95
 
110
- <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Anchormodels</span><span class='op'>::</span><span class='const'>Role</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
96
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Role</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="Anchormodel.html" title="Anchormodel (class)">Anchormodel</a></span></span>
97
+ <span class='comment'># Make &lt;, &gt; etc. based on &lt;=&gt; operator whic hwe will define below
98
+ </span> <span class='id identifier rubyid_include'>include</span> <span class='const'>Comparable</span>
99
+
111
100
  <span class='comment'># Expose the attribute privilege_level
112
101
  </span> <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:privilege_level</span>
113
102
 
114
- <span class='comment'># Overload &lt;=&gt; to make user roles comparable based on the privilege level
103
+ <span class='comment'># Define &lt;=&gt; to make user roles comparable based on the privilege level
115
104
  </span> <span class='kw'>def</span> <span class='op'>&lt;=&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
116
- <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span> <span class='op'>&lt;=&gt;</span> <span class='ivar'>@privilege_level</span>
105
+ <span class='ivar'>@privilege_level</span> <span class='op'>&lt;=&gt;</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span>
117
106
  <span class='kw'>end</span>
118
107
 
119
108
  <span class='comment'># Declare all available roles
@@ -134,10 +123,10 @@ entries of an Anchormodel.</p>
134
123
  <p>You may now use the following methods:</p>
135
124
 
136
125
  <pre class="code ruby"><code class="ruby"><span class='comment'># Retrieve all user roles:
137
- </span><span class='const'>Anchormodels</span><span class='op'>::</span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span>
126
+ </span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span>
138
127
 
139
128
  <span class='comment'># Retrieve a specific role from the String and find its privilege level
140
- </span><span class='const'>Anchormodels</span><span class='op'>::</span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:guest</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span>
129
+ </span><span class='const'>Role</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:guest</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_privilege_level'>privilege_level</span>
141
130
 
142
131
  <span class='comment'># Implement a Rails helper that makes sure users can only edit other users that have a lower privilege level than themselves
143
132
  </span><span class='kw'>def</span> <span class='id identifier rubyid_user_can_edit?'>user_can_edit?</span><span class='lparen'>(</span><span class='id identifier rubyid_this_user'>this_user</span><span class='comma'>,</span> <span class='id identifier rubyid_other_user'>other_user</span><span class='rparen'>)</span>
@@ -148,18 +137,18 @@ entries of an Anchormodel.</p>
148
137
  </span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>User </span><span class='embexpr_beg'>#{</span><span class='ivar'>@user</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'> has role </span><span class='embexpr_beg'>#{</span><span class='ivar'>@user</span><span class='period'>.</span><span class='id identifier rubyid_role'>role</span><span class='period'>.</span><span class='id identifier rubyid_label'>label</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
149
138
  </code></pre>
150
139
 
151
- <h1 id="installation">Installation</h1>
152
-
153
- <ol>
154
- <li>Add gem to Gemfile: <code>gem &#39;anchormodel&#39;</code></li>
155
- <li>In <code>application_record.rb</code>, add in the class body: <code>include Anchormodel::ModelMixin</code></li>
156
- </ol>
140
+ <h1 id="label-Installation">Installation</h1>
141
+ <ol><li>
142
+ <p>Add gem to Gemfile: <code>gem &#39;anchormodel&#39;</code></p>
143
+ </li><li>
144
+ <p>In <code>application_record.rb</code>, add in the class body: <code>include Anchormodel::ModelMixin</code></p>
145
+ </li></ol>
157
146
  </div></div>
158
147
 
159
148
  <div id="footer">
160
- Generated on Sat Dec 17 12:56:00 2022 by
149
+ Generated on Wed Jan 18 11:24:43 2023 by
161
150
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
162
- 0.9.28 (ruby-3.0.4).
151
+ 0.9.28 (ruby-3.1.3).
163
152
  </div>
164
153
 
165
154
  </div>
data/doc/method_list.html CHANGED
@@ -189,6 +189,14 @@
189
189
 
190
190
 
191
191
  <li class="odd ">
192
+ <div class="item">
193
+ <span class='object_link'><a href="Anchormodel.html#setup!-class_method" title="Anchormodel.setup! (method)">setup!</a></span>
194
+ <small>Anchormodel</small>
195
+ </div>
196
+ </li>
197
+
198
+
199
+ <li class="even ">
192
200
  <div class="item">
193
201
  <span class='object_link'><a href="Anchormodel.html#to_s-instance_method" title="Anchormodel#to_s (method)">#to_s</a></span>
194
202
  <small>Anchormodel</small>
@@ -100,9 +100,9 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sat Dec 17 12:56:00 2022 by
103
+ Generated on Wed Jan 18 11:24:43 2023 by
104
104
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
- 0.9.28 (ruby-3.0.4).
105
+ 0.9.28 (ruby-3.1.3).
106
106
  </div>
107
107
 
108
108
  </div>
@@ -7,12 +7,12 @@ class Anchormodel::Attribute
7
7
 
8
8
  # @param model_class [ActiveRecord::Base] The Rails model where {Anchormodel::ModelMixin#belongs_to_anchormodel} is used
9
9
  # @param attribute_name [String,Symbol] The name and database column of the attribute
10
- # @param anchor_class_name [String] Name of the Anchormodel class (omit if attribute `:foo_bar` holds an `Anchormodels::FooBar`)
10
+ # @param anchor_class_name [String] Name of the Anchormodel class (omit if attribute `:foo_bar` holds an `FooBar`)
11
11
  # @param optional [Boolean] If true, a presence validation is added to the model.
12
12
  def initialize(model_class, attribute_name, anchor_class_name = nil, optional = false)
13
13
  @model_class = model_class
14
14
  @attribute_name = attribute_name.to_sym
15
- @anchor_class_name = anchor_class_name || "Anchormodels::#{attribute_name.to_s.classify}"
15
+ @anchor_class_name = anchor_class_name || attribute_name.to_s.classify
16
16
  @optional = optional
17
17
  end
18
18
 
@@ -11,7 +11,7 @@ module Anchormodel::ModelMixin
11
11
  # Creates an attribute linking to an Anchormodel. The attribute should be
12
12
  # present in the DB and the column should be named the same as `attribute_name.`
13
13
  # @param attribute_name [String,Symbol] The name and database column of the attribute
14
- # @param anchor_class_name [String] Name of the Anchormodel class (omit if attribute `:foo_bar` holds an `Anchormodels::FooBar`)
14
+ # @param anchor_class_name [String] Name of the Anchormodel class (omit if attribute `:foo_bar` holds a `FooBar`)
15
15
  # @param optional [Boolean] If true, a presence validation is added to the model.
16
16
  def belongs_to_anchormodel(attribute_name, anchor_class_name = nil, optional: false)
17
17
  attribute_name = attribute_name.to_sym
@@ -1,8 +1,8 @@
1
1
  class Anchormodel
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 0
5
- PATCH = 2
4
+ MINOR = 1
5
+ PATCH = 0
6
6
 
7
7
  EDGE = false
8
8
 
data/lib/anchormodel.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # @api description
2
- # Inherit from this class and place your Anchormodel under `app/anchormodels/your_anchor_model.rb`. Use it like `Anchormodels::YourAnchorModel`.
2
+ # Inherit from this class and place your Anchormodel under `app/anchormodels/your_anchor_model.rb`. Use it like `YourAnchorModel`.
3
3
  # Refer to the README for usage.
4
4
  class Anchormodel
5
5
  attr_reader :key
@@ -13,7 +13,7 @@ class Anchormodel
13
13
  # When a descendant of Anchormodel is first used, it must overwrite the class_attributes
14
14
  # to prevent cross-class pollution.
15
15
  def self.setup!
16
- fail("`setup!` was called twice for Anchormodel subclass #{to_s}.") if setup_completed
16
+ fail("`setup!` was called twice for Anchormodel subclass #{self}.") if setup_completed
17
17
  self.entries_list = entries_list.dup
18
18
  self.entries_hash = entries_hash.dup
19
19
  self.valid_keys = valid_keys.dup
data/logo.svg ADDED
@@ -0,0 +1,98 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
4
+ xmlns:cc="http://creativecommons.org/ns#"
5
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6
+ xmlns:svg="http://www.w3.org/2000/svg"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ xmlns:xlink="http://www.w3.org/1999/xlink"
9
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
10
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
11
+ width="156.75362mm"
12
+ height="164.14165mm"
13
+ viewBox="0 0 156.75362 164.14165"
14
+ version="1.1"
15
+ id="svg8"
16
+ inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
17
+ sodipodi:docname="logo.svg">
18
+ <defs
19
+ id="defs2">
20
+ <linearGradient
21
+ inkscape:collect="always"
22
+ id="linearGradient900">
23
+ <stop
24
+ style="stop-color:#1b252e;stop-opacity:1"
25
+ offset="0"
26
+ id="stop896" />
27
+ <stop
28
+ style="stop-color:#551544;stop-opacity:1"
29
+ offset="1"
30
+ id="stop898" />
31
+ </linearGradient>
32
+ <linearGradient
33
+ inkscape:collect="always"
34
+ xlink:href="#linearGradient900"
35
+ id="linearGradient902"
36
+ x1="86.611481"
37
+ y1="46.172035"
38
+ x2="28.230343"
39
+ y2="199.08452"
40
+ gradientUnits="userSpaceOnUse" />
41
+ </defs>
42
+ <sodipodi:namedview
43
+ id="base"
44
+ pagecolor="#ffffff"
45
+ bordercolor="#666666"
46
+ borderopacity="1.0"
47
+ inkscape:pageopacity="0.0"
48
+ inkscape:pageshadow="2"
49
+ inkscape:zoom="0.7"
50
+ inkscape:cx="265.73964"
51
+ inkscape:cy="446.69416"
52
+ inkscape:document-units="mm"
53
+ inkscape:current-layer="layer1"
54
+ inkscape:document-rotation="0"
55
+ showgrid="false"
56
+ inkscape:window-width="3436"
57
+ inkscape:window-height="1401"
58
+ inkscape:window-x="1920"
59
+ inkscape:window-y="18"
60
+ inkscape:window-maximized="1"
61
+ fit-margin-top="0"
62
+ fit-margin-left="0"
63
+ fit-margin-right="0"
64
+ fit-margin-bottom="0" />
65
+ <metadata
66
+ id="metadata5">
67
+ <rdf:RDF>
68
+ <cc:Work
69
+ rdf:about="">
70
+ <dc:format>image/svg+xml</dc:format>
71
+ <dc:type
72
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
73
+ <dc:title></dc:title>
74
+ </cc:Work>
75
+ </rdf:RDF>
76
+ </metadata>
77
+ <g
78
+ inkscape:label="Ebene 1"
79
+ inkscape:groupmode="layer"
80
+ id="layer1"
81
+ transform="translate(-17.637819,-39.186618)">
82
+ <g
83
+ id="g908">
84
+ <path
85
+ id="path892"
86
+ style="fill:#1b252e;fill-opacity:1;stroke-width:0.15337"
87
+ d="m 95.252639,194.5457 c -1.41201,-0.23145 -5.03489,-1.03694 -6.05811,-1.34693 -0.67482,-0.20442 -1.45547,-0.42833 -1.73476,-0.49756 -0.2793,-0.0692 -0.5054,-0.17869 -0.50245,-0.24326 0.003,-0.0646 0.33499,-0.39855 0.73786,-0.74216 2.81821,-2.40369 7.0189,-6.93571 9.78801,-10.56003 1.65518,-2.16638 4.418551,-6.26673 5.590951,-8.29601 l 0.91492,-1.58362 0.17975,0.51562 c 0.19829,0.56881 3.1596,6.44921 3.34949,6.65122 0.23843,0.25364 6.5474,-2.86237 9.51285,-4.69841 0.97006,-0.60061 2.14334,-1.35392 2.60728,-1.67403 0.46395,-0.32011 0.97448,-0.66761 1.13452,-0.77224 0.32704,-0.2138 2.00088,-1.48828 3.4727,-2.64414 2.6923,-2.11434 8.57098,-7.66106 11.05332,-10.42915 1.08345,-1.20817 3.53989,-4.20374 4.27607,-5.21457 0.3686,-0.50612 0.70991,-0.95472 0.75846,-0.9969 0.3503,-0.30429 0.94266,-1.27968 0.87857,-1.44669 -0.13018,-0.33925 -1.78342,-1.15491 -3.14808,-1.55317 -2.09639,-0.61181 -3.58423,-0.49323 -4.98895,0.39762 -0.68157,0.43223 -0.76661,0.45123 -1.08534,0.24239 -0.1966,-0.12882 -0.41527,-0.50019 -0.50676,-0.86065 -0.19706,-0.77636 0.1249,-2.05053 0.87227,-3.45196 0.95415,-1.78921 4.53453,-6.34984 7.75721,-9.88103 1.99573,-2.18677 8.71813,-8.76843 10.85401,-10.62675 0.45764,-0.39817 1.1309,-1.00538 1.49612,-1.34935 0.36522,-0.34396 0.7496,-0.67384 0.85418,-0.73306 0.10458,-0.0592 0.48951,-0.38373 0.8554,-0.72114 2.0724,-1.9111 5.20704,-4.52441 5.42698,-4.52441 0.25342,0 0.92126,0.77425 1.25677,1.45701 0.36828,0.74943 1.19233,4.00134 1.59346,6.28816 0.42098,2.39999 0.59505,5.00463 0.60006,8.97888 0.006,4.39041 -0.34888,8.26542 -1.00238,10.95919 -0.12278,0.50612 -0.43073,1.78355 -0.68434,2.83874 -0.79619,3.31272 -2.2497,7.14262 -4.42316,11.65471 -0.7693,1.59704 -2.35022,4.34476 -3.10098,5.38962 l -0.40127,0.55847 -0.42764,-1.24864 c -0.95987,-2.80272 -2.35482,-5.21065 -4.09834,-7.07448 -1.03208,-1.1033 -1.44582,-1.28089 -1.2857,-0.55186 0.0673,0.30648 0.0301,0.4875 -0.11828,0.57514 -0.11909,0.0703 -0.48563,0.54198 -0.81455,1.0481 -0.32892,0.50612 -0.65223,0.98924 -0.71846,1.07359 -0.0662,0.0844 -0.5863,0.84354 -1.15571,1.68707 -2.54545,3.77086 -4.09551,5.91646 -5.59537,7.74517 -0.10378,0.12653 -0.39457,0.50601 -0.64621,0.84328 -1.27223,1.70519 -3.75133,4.52325 -5.67119,6.44656 -2.96589,2.97124 -4.10665,3.96217 -7.13581,6.19861 -0.63441,0.4684 -1.35909,1.00484 -1.61038,1.19211 -4.1958,3.12669 -10.47563,6.40426 -15.94724,8.32321 -2.52792,0.88655 -5.96165,1.85402 -7.66849,2.16061 -0.42177,0.0758 -1.284471,0.24206 -1.917121,0.36957 -1.07882,0.21741 -2.49852,0.27109 -3.37414,0.12755 z m -38.34245,-20.90135 c -0.37959,-0.0587 -1.19903,-0.26582 -1.82097,-0.46029 -1.4476,-0.45264 -2.20148,-1.18893 -4.19844,-4.10042 -0.35869,-0.52297 -1.16979,-1.63497 -1.80244,-2.47113 -0.63265,-0.83616 -1.27152,-1.68509 -1.41972,-1.8865 -0.37675,-0.51208 -3.37187,-5.08288 -5.28024,-8.0581 -0.16684,-0.26012 -0.25187,-0.21114 -1.03747,0.59763 -1.0352,1.06572 -2.41226,3.14361 -3.18142,4.80055 -1.01247,2.18107 -1.35074,2.96208 -1.35074,3.11869 0,0.39455 -0.30952,0.27056 -0.6243,-0.25008 -0.38393,-0.635 -3.05657,-5.56477 -3.05657,-5.63794 0,-0.0253 -0.34499,-0.77007 -0.76666,-1.65512 -3.62493,-7.60865 -5.36989,-15.78016 -5.16469,-24.18585 0.1149,-4.70644 0.52571,-7.94843 1.56449,-12.34627 0.60555,-2.5637 0.94317,-3.10491 2.02771,-3.25038 0.58994,-0.0791 0.6355,-0.0472 3.11765,2.18416 3.69543,3.32209 3.65849,3.28929 4.82122,4.28084 0.58952,0.50274 1.624,1.44045 2.29882,2.0838 0.67483,0.64335 1.60587,1.50882 2.06897,1.92327 1.38935,1.24336 6.59798,6.48742 7.83197,7.88523 2.85563,3.23474 5.41308,6.48762 6.87312,8.74208 1.15489,1.78328 1.34304,3.21188 0.6198,4.7059 l -0.31773,0.65634 -0.3911,-0.4648 c -1.43941,-1.71064 -4.31582,-1.71196 -7.71289,-0.004 -0.66458,0.33422 -1.14374,0.67122 -1.1348,0.79809 0.027,0.38279 3.37081,4.70913 5.4964,7.11143 3.28049,3.70752 7.9538,8.33881 11.18029,11.07975 1.08387,0.92077 2.7743,2.29046 3.0687,2.48646 0.18181,0.12105 0.56345,0.38991 0.84807,0.59747 l 0.5175,0.37739 -1.13098,0.2903 c -1.81773,0.46657 -4.12807,0.88567 -5.75426,1.04382 -1.6988,0.16521 -5.14143,0.16922 -6.18929,0.007 z" />
88
+ <path
89
+ style="fill:#1b252e;fill-opacity:1;stroke-width:0.15337"
90
+ d="m 73.138899,201.72191 -0.56528,-0.0933 1.4855,-0.68276 c 0.81703,-0.37552 2.14116,-1.05816 2.94252,-1.51696 0.80135,-0.45879 1.66406,-0.95169 1.91712,-1.09532 0.25306,-0.14363 1.12505,-0.68768 1.93776,-1.20899 l 1.47765,-0.94784 1.20632,0.59575 c 3.11279,1.53728 11.07339,3.39783 13.69965,3.20187 2.761661,-0.20603 9.355601,-1.83619 11.892461,-2.94002 0.25306,-0.1101 0.8397,-0.35341 1.30365,-0.54067 0.46394,-0.18725 1.41453,-0.64405 2.11243,-1.01508 1.17819,-0.62639 1.31523,-0.66441 1.91712,-0.53179 0.35652,0.0786 1.64896,0.21806 2.87209,0.31 1.22312,0.092 2.91402,0.23168 3.75756,0.3105 0.84353,0.0788 2.60345,0.21832 3.91093,0.31002 1.30747,0.0917 3.13641,0.23564 4.0643,0.31985 0.92788,0.0842 3.20542,0.24923 5.0612,0.36669 1.85577,0.11747 6.68692,0.45761 10.73588,0.75589 4.04896,0.29827 9.39774,0.68404 11.88616,0.85726 2.48842,0.17323 5.35261,0.38212 6.36485,0.46422 1.01224,0.0821 2.80666,0.21473 3.98761,0.29476 1.18095,0.08 3.3032,0.23076 4.71612,0.33496 l 2.56894,0.18947 v 1.10058 1.1006 l -0.94271,0.0985 c -1.19572,0.12499 -99.547791,0.0875 -100.309831,-0.0383 z"
91
+ id="path890" />
92
+ <path
93
+ style="fill:url(#linearGradient902);fill-opacity:1;stroke-width:0.15337"
94
+ d="m 41.036419,203.29922 c -6.6454,-0.25704 -14.21974,-1.23751 -21.01166,-2.71988 l -2.30054,-0.50212 -0.0432,-1.79323 -0.0432,-1.79323 h 0.37904 c 0.20848,0 1.60825,0.10136 3.11061,0.22524 10.63489,0.87692 22.45948,0.90484 29.34121,0.0693 3.76481,-0.45712 5.8148,-0.86537 9.6623,-1.92425 1.10377,-0.30376 4.02123,-1.29358 4.21767,-1.43096 0.0843,-0.059 0.49845,-0.23296 0.92022,-0.38663 1.13997,-0.41532 4.5733,-2.14947 6.03707,-3.04928 0.70543,-0.43364 1.45985,-0.89494 1.67649,-1.02512 0.21664,-0.13016 0.42066,-0.317 0.45339,-0.41517 0.0335,-0.10047 -0.6994,-0.55901 -1.6765,-1.04892 -1.8084,-0.90672 -4.36159,-2.39156 -5.41686,-3.15024 -0.33742,-0.24258 -1.13111,-0.81303 -1.76376,-1.26766 -0.63265,-0.45464 -1.25654,-0.92032 -1.38643,-1.03485 -0.12989,-0.11452 -0.65371,-0.49821 -1.16405,-0.85262 -0.77073,-0.53524 -1.2576,-0.72503 -2.87437,-1.12049 -2.86906,-0.70177 -4.85117,-1.66258 -8.5316,-4.13561 -0.92776,-0.62339 -0.79088,-0.78248 0.26097,-0.30332 4.46726,2.03499 8.71337,2.87048 13.77217,2.70988 4.10395,-0.13028 7.45721,-0.94969 11.11931,-2.71714 2.09711,-1.01213 4.1177,-2.38394 6.12915,-4.16117 3.41928,-3.02112 5.88138,-6.87339 6.75097,-10.56273 0.27091,-1.14937 0.35977,-2.0885 0.42086,-4.44773 0.0735,-2.83832 0.0532,-3.13138 -0.39818,-5.75136 -0.50005,-2.90249 -0.94333,-4.79646 -1.7208,-7.3525 -0.95328,-3.13399 -1.86555,-6.01802 -2.2103,-6.98758 -0.74485,-2.09477 -2.2714,-7.21923 -2.74129,-9.20218 -0.62085,-2.62001 -0.90852,-4.85573 -0.90778,-7.05501 7.7e-4,-2.21786 0.0982,-2.96973 0.68586,-5.29126 0.39846,-1.57416 0.5011,-1.85373 1.31563,-3.58354 0.67742,-1.43865 2.0959,-3.66606 3.95402,-6.20893 1.25993,-1.72424 1.56117,-2.64487 1.30591,-3.99108 -0.17761,-0.93673 -0.65101,-2.473533 -0.91673,-2.976013 -0.0769,-0.14547 -0.35663,-0.70099 -0.62156,-1.23449 -0.26494,-0.5335 -0.72881,-1.3617 -1.03083,-1.84044 -0.97191,-1.54057 -1.94825,-3.01305 -2.11117,-3.184 -0.0872,-0.0915 -0.29662,-0.35868 -0.46533,-0.59369 -1.09629,-1.52715 -2.45246,-3.15178 -2.59373,-3.10716 -0.0918,0.029 -0.55825,0.84197 -1.03654,1.80661 -0.47829,0.96464 -0.94415,1.83725 -1.03525,1.93913 -0.0911,0.10188 -0.16563,0.22329 -0.16563,0.26979 0,0.12574 -1.57103,2.69246 -2.7724,4.52949 -1.44789,2.21397 -1.72104,2.75714 -2.43907,4.850033 -0.66067,1.9257 -0.81545,2.30074 -1.60621,3.89205 -1.03911,2.09106 -1.69309,3.09169 -4.07081,6.22862 -0.63224,0.8341 -1.18813,1.55106 -1.23532,1.59324 -0.21602,0.19306 -3.42321,4.39195 -4.84529,6.34349 -2.07985,2.85422 -1.88564,2.61561 -3.22535,3.96265 -1.37051,1.37802 -2.12769,1.81163 -5.01634,2.8727 -1.17075,0.43004 -2.58559,1.01805 -3.14408,1.30668 -0.9721,0.50238 -2.11381,1.00482 -2.28331,1.00482 -0.0441,0 -0.0377,-0.45438 0.0142,-1.00974 0.10865,-1.16347 0.414,-1.73937 1.4081,-2.65569 0.75852,-0.69918 0.80168,-0.8047 0.44893,-1.09746 -0.19524,-0.16204 -0.57385,-0.16458 -2.02246,-0.0136 -1.89867,0.19791 -2.35014,0.37554 -3.15661,1.24198 -0.23912,0.2569 -0.56594,0.4671 -0.72625,0.4671 -0.28385,0 -0.28353,-0.0131 0.0124,-0.49846 0.24797,-0.40669 0.30401,-0.77371 0.30448,-1.9938 l 5.8e-4,-1.49537 0.65183,-0.009 c 0.3585,-0.005 0.9969,-0.0737 1.41867,-0.15267 1.01064,-0.18915 3.29519,-0.58008 4.44772,-0.76109 0.50612,-0.0795 1.2653,-0.14672 1.68707,-0.14942 1.03433,-0.007 2.2882,-0.35796 2.97428,-0.83341 2.15787,-1.49541 3.65872,-3.97932 7.09614,-11.74417 2.19522,-4.95879 2.98763,-6.36418 4.70631,-8.346903 1.52839,-1.76319 2.14727,-3.3015 3.39833,-8.44709 0.34866,-1.43401 0.79363,-3.19393 0.98883,-3.91093 0.1952,-0.71701 0.57889,-2.13184 0.85263,-3.14408 0.90123,-3.33253 1.95174,-5.89998 2.85166,-6.96947 0.22999,-0.27333 1.21767,-1.03368 2.19484,-1.68967 1.62375,-1.09003 4.00077,-3.04778 4.13072,-3.40211 0.0294,-0.0802 0.27661,-0.47739 0.54931,-0.88262 0.7353,-1.092652 0.622173,-2.172714 0.65428,-3.700167 0.135499,-1.114491 0.04248,-1.98501 0.04367,-2.882257 -0.003,-1.098313 -6.1e-4,-1.09281 -1.46118,-3.198177 -1.1186,-1.612407 -1.4619,-2.337314 -1.97395,-4.168128 -0.27794,-0.993778 -0.60222,-2.009572 -0.72062,-2.257321 -0.24391,-0.51039 -0.84841,-0.693314 -0.99851,-0.302154 -0.10313,0.268734 0.13857,2.701444 0.3662,3.685946 0.32225,1.393673 1.42421,3.530014 3.00588,5.827421 0.23227,0.337383 0.31705,0.704178 0.31905,1.380328 0.005,1.553322 -0.49519,4.517177 -0.9494,5.630359 -0.38865,0.95248 -0.4709,1.04784 -1.11098,1.2881 -1.00238,0.37624 -2.38129,1.15619 -3.47422,1.96511 -2.1279,1.57496 -3.1697,3.36476 -4.87586,8.37664 -0.84438,2.48041 -1.2728,3.16177 -2.68653,4.27269 -1.82955,1.43767 -3.8035,2.14778 -5.99871,2.15798 -2.13629,0.01 -3.67499,-0.46323 -5.39381,-1.65858 -2.71034,-1.88491 -4.14318,-5.54123 -3.50238,-8.93734 0.43441,-2.30231 1.9869,-4.12525 4.23872,-4.97713 0.92571,-0.3502 1.23232,-0.39351 2.3671,-0.33435 2.65672,0.1385 4.66571,1.70352 5.21081,4.05927 0.39962,1.72706 -0.55389,3.80536 -2.02346,4.41038 -0.77856,0.32053 -1.08281,0.29571 -1.47355,-0.12021 -0.27559,-0.29335 -0.33388,-0.53961 -0.33582,-1.41867 -10e-4,-0.58504 -0.064,-1.16103 -0.13925,-1.27997 -0.0795,-0.12555 -0.48059,-0.24387 -0.95622,-0.28206 -0.67523,-0.0542 -0.91122,-0.003 -1.342,0.29295 -0.88662,0.60853 -1.14833,1.09576 -1.21414,2.26046 -0.072,1.27419 0.24674,2.10751 1.20281,3.14472 0.98007,1.06325 2.09255,1.53941 3.60142,1.54148 1.75379,0.002 2.76495,-0.42961 4.07913,-1.74274 1.03331,-1.0325 1.34866,-1.58329 1.98544,-3.46778 0.407,-1.20445 0.42441,-1.80436 0.3093,-10.65627 -0.0606,-4.661608 -0.0594,-4.684396 0.36585,-6.592133 0.28751,-1.289968 0.79721,-2.831455 1.5627,-4.726147 1.17206,-2.900981 1.61924,-4.392044 2.27888,-7.598724 0.97966,-4.762375 1.57007,-6.945514 2.22608,-8.231402 0.51784,-1.015058 1.52018,-1.995741 2.5296,-2.474959 0.7469,-0.354584 1.12243,-0.435623 1.99381,-0.430258 0.59047,0.0036 1.34232,0.102385 1.67077,0.219442 0.57999,0.2067 0.637209,-0.0049 1.211549,-0.466417 0.32525,-0.261381 1.673725,-0.588873 1.726835,-0.535763 0.0531,0.05311 -1.088622,0.397568 -1.310402,0.49862 -0.22178,0.10105 -0.461412,0.380558 -0.461412,0.446628 0,0.06607 0.29332,-0.0093 0.65182,-0.167561 0.3585,-0.158228 1.33077,-0.443393 2.1606,-0.6337 1.81498,-0.416234 2.60115,-0.312694 4.35945,0.574145 1.03611,0.522586 1.2825,0.686003 2.11109,1.400215 0.43396,0.374058 2.92248,3.285079 3.83456,4.485588 0.41656,0.548297 0.9862,1.259647 1.26586,1.580777 0.62539,0.718121 1.54268,2.122096 1.92324,2.943632 0.1563,0.337413 0.54704,1.5452 0.86831,2.683971 0.562141,1.992564 0.676201,2.779197 1.010581,6.969582 0.0535,0.670019 0.20039,1.375683 0.32649,1.56814 0.1261,0.192458 0.58483,0.526634 1.01939,0.742614 0.43456,0.21598 0.95066,0.526382 1.14689,0.68978 0.47426,0.600469 -0.14673,0.833732 -0.40181,1.041679 -0.25508,0.207946 -0.58883,0.395371 -0.90814,0.499476 -0.31932,0.104106 -0.61508,0.23235 -0.65726,0.28499 -0.0422,0.05264 -0.5598,0.260238 -1.15027,0.461329 -0.590481,0.201089 -1.071266,0.363914 -1.226961,0.477834 -0.155695,0.11392 -0.94054,0.28929 -2.14718,0.370661 -0.80124,0.05403 -1.40429,-0.01422 -2.37723,-0.269023 -1.61172,-0.422106 -1.6866,-0.469764 -1.68903,-1.074984 -0.002,-0.451312 0.39004,-2.486038 0.58161,-3.020001 0.0454,-0.12653 0.0702,-0.285825 0.0552,-0.35399 -0.015,-0.06816 0.0735,-0.344229 0.19671,-0.613479 0.12322,-0.269248 0.29976,-0.782864 0.39231,-1.141366 0.0925,-0.358501 0.131394,-0.412415 0.31573,-0.651821 0.184336,-0.239406 0.289784,-1.126088 0.43993,-1.610383 0.36651,-1.169012 0.5758,-2.99071 0.3436,-2.99071 -0.0916,0 -0.43265,0.138718 -0.75793,0.308262 -0.5429,0.282977 -0.60753,0.386765 -0.78792,1.265301 -0.10808,0.526371 -0.24376,1.312196 -0.30151,1.74628 -0.0577,0.434083 -0.18192,0.882689 -0.27592,0.996904 -0.094,0.114213 -0.62604,1.052204 -1.18229,2.084422 0,0 -0.841451,1.186734 -1.01137,1.876762 -0.107127,0.435035 0.0153,1.344004 0.0153,1.344004 0.0182,1.600573 0.0806,1.845164 0.65351,2.56016 0.623124,0.55109 1.352525,0.794081 2.0373,1.155699 0.6579,0.328575 0.84199,0.348892 2.41114,0.266112 1.16041,-0.06122 1.254704,-0.122688 1.85666,-0.297303 0.642834,-0.186473 0.91697,-0.470992 1.84486,-0.792819 3.899401,-1.35246 7.483391,-3.374538 10.735891,-6.057173 1.55617,-1.283521 1.75239,-1.518013 1.75865,-2.101667 0.005,-0.490661 -0.64786,-1.213611 -2.24614,-2.486319 -0.35129,-0.279733 -0.83392,-0.678505 -1.07252,-0.886162 -0.23859,-0.207655 -1.00807,-0.806978 -1.70996,-1.33183 -0.70189,-0.524852 -1.80751,-1.368375 -2.45693,-1.874495 -0.64942,-0.50612 -1.59351,-1.227819 -2.09797,-1.603774 -2.535681,-1.889723 -4.859941,-4.123792 -6.676631,-6.417541 l -0.64385,-0.812935 0.44097,0.100144 c 0.91942,0.208796 4.838831,1.622861 8.262841,2.981114 1.0966,0.435002 2.61496,1.020191 3.37414,1.300421 0.75918,0.28023 1.75992,0.678509 2.22386,0.885065 0.46394,0.206555 1.08509,0.467641 1.38033,0.580191 1.11913,0.426633 4.58414,2.172877 6.51299,3.282316 1.57117,0.903706 2.77182,1.751643 3.62712,2.561578 0.59559,0.563993 0.74914,0.810951 0.74914,1.20482 0,0.757136 -0.42232,2.222 -0.99019,3.434607 -0.53562,1.143729 -2.56065,4.792558 -2.83717,5.112184 -0.0881,0.101882 -0.16217,0.239915 -0.16452,0.30674 -0.60418,1.029727 -2.00307,2.263117 -2.41131,2.783035 -0.40824,0.519918 -1.69849,1.716624 -4.33269,3.496545 -0.46395,0.31349 -0.87804,0.61584 -0.92022,0.67189 -0.0422,0.056 -0.42177,0.29253 -0.84354,0.52551 -1.19968,0.66271 -5.75136,4.20502 -5.75136,4.47596 0,0.0505 0.408,0.51482 0.90667,1.03183 1.61495,1.67435 2.00088,2.15258 2.42948,3.0105 0.37135,0.74334 0.42141,1.01756 0.42141,2.30861 0,1.39567 -0.0285,1.52282 -0.60244,2.68392 -0.46595,0.94269 -0.87338,1.48048 -1.79826,2.37361 l -1.19582,1.15477 -0.17356,2.25314 c -0.26642,3.45867 0.19766,7.08283 1.15125,8.990473 0.78726,1.57491 0.94599,1.83667 1.91876,3.16427 0.55627,0.75918 1.12942,1.55286 1.27366,1.76375 0.36382,0.53192 1.76725,2.4972 1.91666,2.68397 0.21959,0.27449 1.52957,2.4397 1.80811,2.98854 0.75105,1.47985 1.62724,4.77847 2.01715,7.59397 0.2087,1.50697 0.27278,2.91131 0.26247,5.75137 -0.0231,6.37299 -0.79293,11.84404 -2.88083,20.47486 -0.26096,1.07875 -2.07571,6.98039 -2.52312,8.20529 -0.16946,0.46394 -0.44182,1.18861 -0.60523,1.61038 -0.16342,0.42177 -0.59173,1.56054 -0.95182,2.5306 -0.805,2.16866 -1.04508,2.70476 -2.85029,6.36485 -1.53141,3.10495 -2.3526,4.65426 -3.03431,5.72469 -0.23241,0.36492 -0.46494,0.77902 -0.51674,0.92022 -0.19674,0.53623 -4.705301,7.32677 -5.109191,7.69516 -0.0462,0.0422 -0.24994,0.31824 -0.45267,0.61348 -0.40722,0.59306 -2.93585,3.64605 -3.6203,4.37104 -0.23891,0.25306 -0.73922,0.80519 -1.11181,1.22696 -1.88944,2.1388 -4.64263,4.78285 -6.69399,6.42863 -0.59047,0.47373 -1.24613,1.00166 -1.45701,1.17318 -2.71644,2.2094 -9.36833,5.9623 -12.33487,6.95917 -0.41551,0.13962 -1.07116,0.38234 -1.45702,0.53937 -1.07847,0.43893 -3.00962,1.0293 -4.5358,1.38662 -0.75918,0.17776 -1.62242,0.38632 -1.9183,0.4635 -1.81895,0.47439 -5.74384,1.07173 -9.58443,1.45871 -2.176,0.21926 -8.51635,0.38314 -11.04263,0.28543 z"
95
+ id="path847" />
96
+ </g>
97
+ </g>
98
+ </svg>
@@ -0,0 +1,51 @@
1
+ class UserTest < Minitest::Test
2
+ def setup; end
3
+
4
+ def test_retrieval
5
+ assert_equal Role.find(:guest), Role.find('guest')
6
+ end
7
+
8
+ def test_collections
9
+ # Order must fit as well
10
+ assert_equal(
11
+ %i[guest moderator admin the_chosen_one].map { |key| Role.find(key) },
12
+ Role.all
13
+ )
14
+ assert_equal(
15
+ %i[en de fr it].map { |key| Locale.find(key) },
16
+ Locale.all
17
+ )
18
+ end
19
+
20
+ def test_setters_and_getters
21
+ u = User.create!(role: 'guest', locale: 'de') # String assignment
22
+ assert_equal Role.find(:guest), u.role
23
+ assert_equal Locale.find(:de), u.locale
24
+ u.update!(role: :admin, locale: Locale.find(:en)) # Symbol and Anchormodel assignemnt
25
+ assert_equal Role.find(:admin), u.role
26
+ assert_equal Locale.find(:en), u.locale
27
+ end
28
+
29
+ def test_comparison
30
+ bob = User.create(locale: :en)
31
+ alice = User.create(locale: :fr)
32
+ celine = User.create(locale: :fr)
33
+ assert_equal(alice.locale, celine.locale)
34
+ assert bob.locale != alice.locale
35
+ end
36
+
37
+ def test_attributes
38
+ # Standalone
39
+ assert_equal 0, Role.find(:guest).privilege_level
40
+ # With a model
41
+ u = User.create(role: :the_chosen_one)
42
+ assert_equal 42, u.role.privilege_level
43
+ end
44
+
45
+ def test_custom_comparison
46
+ assert_equal(-1, Role.find(:moderator) <=> Role.find(:admin))
47
+ assert_equal(1, Role.find(:moderator) <=> Role.find(:guest))
48
+ assert_equal(0, Role.find(:moderator) <=> Role.find(:moderator))
49
+ assert Role.find(:moderator) < Role.find(:admin)
50
+ end
51
+ end
@@ -0,0 +1,29 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-*
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore pidfiles, but keep the directory.
21
+ /tmp/pids/*
22
+ !/tmp/pids/
23
+ !/tmp/pids/.keep
24
+
25
+
26
+ /public/assets
27
+
28
+ # Ignore master key for decrypting credentials and more.
29
+ /config/master.key
@@ -0,0 +1,6 @@
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_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,6 @@
1
+ class Locale < Anchormodel
2
+ new :en
3
+ new :de
4
+ new :fr
5
+ new :it
6
+ end
@@ -0,0 +1,14 @@
1
+ class Role < Anchormodel
2
+ include Comparable
3
+
4
+ attr_reader :privilege_level
5
+
6
+ new :guest, privilege_level: 0
7
+ new :moderator, privilege_level: 1
8
+ new :admin, privilege_level: 2
9
+ new :the_chosen_one, privilege_level: 42
10
+
11
+ def <=>(other)
12
+ @privilege_level <=> other.privilege_level
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ include Anchormodel::ModelMixin
3
+
4
+ primary_abstract_class
5
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ class User < ApplicationRecord
2
+ belongs_to_anchormodel :role
3
+ belongs_to_anchormodel :locale
4
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
+
7
+ def system!(*args)
8
+ system(*args) || abort("\n== Command #{args} failed ==")
9
+ end
10
+
11
+ FileUtils.chdir APP_ROOT do
12
+ # This script is a way to set up or update your development environment automatically.
13
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # puts "\n== Copying sample files =="
21
+ # unless File.exist?("config/database.yml")
22
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23
+ # end
24
+
25
+ puts "\n== Preparing database =="
26
+ system! 'bin/rails db:prepare'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ puts "\n== Restarting application server =="
32
+ system! 'bin/rails restart'
33
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'boot'
2
+
3
+ require 'rails'
4
+ # Pick the frameworks you want:
5
+ require 'active_model/railtie'
6
+ # require "active_job/railtie"
7
+ require 'active_record/railtie'
8
+ # require "active_storage/engine"
9
+ # require "action_controller/railtie"
10
+ # require "action_mailer/railtie"
11
+ # require "action_mailbox/engine"
12
+ # require "action_text/engine"
13
+ # require "action_view/railtie"
14
+ # require "action_cable/engine"
15
+ # require "rails/test_unit/railtie"
16
+
17
+ # Require the gems listed in Gemfile, including any gems
18
+ # you've limited to :test, :development, or :production.
19
+ Bundler.require(*Rails.groups)
20
+
21
+ module Dummy
22
+ class Application < Rails::Application
23
+ # Initialize configuration defaults for originally generated Rails version.
24
+ config.load_defaults 7.0
25
+
26
+ # Configuration for the application, engines, and railties goes here.
27
+ #
28
+ # These settings can be overridden in specific environments using the files
29
+ # in config/environments, which are processed later.
30
+ #
31
+ # config.time_zone = "Central Time (US & Canada)"
32
+ # config.eager_load_paths << Rails.root.join("extras")
33
+
34
+ # Don't generate system test files.
35
+ config.generators.system_tests = nil
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
2
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
3
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1 @@
1
+ P7kFGwr6/RaXmQCebyeCrAyHgw+3lIjhK1w0ibCxdg5tKNHKbOq3EAC67l+QqSiww4eAKZ2ShT/dPBFXVNlYlwinxeap/Uu3ZulCjQdZT1GGnv8umlUsvznAe4FXJtBhEyKB60HRcTt/wwqDaz0uUeE1qQNpGbN4h7yQPlIPMMn+6XsBnY+32KYHhsZVwN92oQdR6hjwuethgN31HZtP+F97N3+HKbN9P/Nh778kOyZqZHdQygMWUuLM9ZoNOr8BsmUEonLGZB8stJThhu9sZQHGVafTXPMSw0P3cpPx/PfiU6rjQtOZGsc58e/i/VL6poF0Bd526VGaaHBCXj9rzb8HlgUWzCiJdBi52wVozf8ax9Fg/Rjx0NfVtryScyNvCQQaK/iRrPi3CWjOD0ldgjs7PkMTwvbO18i/--+VAjSXw8o2l4pFRL--EQZXxxTinNbA8IUp8M3i3w==
@@ -0,0 +1,8 @@
1
+ default: &default
2
+ adapter: sqlite3
3
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
4
+ timeout: 5000
5
+
6
+ test:
7
+ <<: *default
8
+ database: db/development.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!