ixtlan 0.4.0.pre2 → 0.4.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java +13 -0
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java +11 -14
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java +2 -7
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java +14 -7
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java +12 -10
- data/generators/ixtlan_datamapper_model/templates/migration.rb +22 -0
- data/generators/ixtlan_datamapper_model/templates/model.rb +2 -2
- data/generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb +2 -0
- data/generators/ixtlan_datamapper_rspec_model/templates/model_spec.rb +8 -5
- data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb +2 -0
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/controller_spec.rb +13 -7
- data/lib/dm-serializer/to_xml.rb +2 -2
- data/lib/ixtlan/controllers/authentications_controller.rb +1 -1
- data/lib/ixtlan/controllers/locales_controller.rb +1 -0
- data/lib/ixtlan/controllers/users_controller.rb +5 -3
- data/lib/ixtlan/models/authentication.rb +1 -3
- data/lib/ixtlan/models/i18n_text.rb +4 -4
- data/lib/ixtlan/models/user.rb +2 -0
- data/lib/ixtlan/models/word.rb +3 -1
- data/lib/ixtlan/modified_by.rb +1 -1
- data/lib/ixtlan/optimistic_persistence.rb +2 -5
- data/lib/ixtlan/rails/migrations.rb +30 -25
- data/lib/ixtlan/rails/unrestful_authentication.rb +1 -1
- data/lib/ixtlan/session.rb +2 -2
- data/lib/ixtlan/simple_client.rb +126 -0
- data/lib/ixtlan/user_logger.rb +0 -1
- data/lib/ixtlan/version.rb +1 -1
- data/lib/models.rb +1 -0
- metadata +267 -219
- data/History.txt +0 -49
- data/MIT-LICENSE +0 -20
- data/Manifest.txt +0 -103
- data/README.txt +0 -86
- data/Rakefile +0 -55
- data/ixtlan_rails_templates.rb +0 -537
- data/whitespace.rb +0 -31
@@ -129,7 +129,7 @@ module Rails
|
|
129
129
|
"#{match}\n\nimport #{java_package}.models.#{class_name}Factory;\nimport #{java_package}.models.#{class_name};\nimport #{java_package}.views.#{plural_name}.#{class_name}Screen;"
|
130
130
|
end
|
131
131
|
gsub_file application_file, /(screenController = [a-zA-Z.]+;)/mi do |match|
|
132
|
-
"#{match}\n\n #{class_name}Factory #{variable}Factory = new #{class_name}Factory(container.repository,\n container.notifications,\n container.userFactory);\n #{class_name}Screen #{variable}Screen = new #{class_name}Screen(container.loadingNotice,\n container.getTextController,\n #{variable}Factory,\n container.session,\n new ResourceBindings<#{class_name}>(),\n container.
|
132
|
+
"#{match}\n\n #{class_name}Factory #{variable}Factory = new #{class_name}Factory(container.repository,\n container.notifications,\n container.userFactory);\n #{class_name}Screen #{variable}Screen = new #{class_name}Screen(container.loadingNotice,\n container.getTextController,\n #{variable}Factory,\n container.session,\n new ResourceBindings<#{class_name}>(),\n container.listeners,\n container.hyperlinkFactory);\n screenController.addScreen(#{variable}Screen, \"#{plural_name}\");"
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -5,12 +5,21 @@ package <%= package %>.views.<%= plural_name %>;
|
|
5
5
|
|
6
6
|
import <%= package %>.models.<%= class_name %>;
|
7
7
|
|
8
|
+
<% if Array(attributes).detect { |a| a.type == :boolean } -%>
|
9
|
+
import de.saumya.gwt.persistence.client.TimestampFactory;
|
10
|
+
<% end -%>
|
8
11
|
import de.saumya.gwt.translation.common.client.GetTextController;
|
9
12
|
import de.saumya.gwt.translation.common.client.widget.ResourceBindings;
|
10
13
|
import de.saumya.gwt.translation.common.client.widget.ResourceFields;
|
14
|
+
<% if Array(attributes).detect { |a| a.type == :boolean } -%>
|
11
15
|
import de.saumya.gwt.translation.gui.client.bindings.CheckBoxBinding;
|
16
|
+
<% end -%>
|
17
|
+
<% if Array(attributes).detect { |a| a.type == :integer } -%>
|
12
18
|
import de.saumya.gwt.translation.gui.client.bindings.IntegerTextBoxBinding;
|
19
|
+
<% end -%>
|
20
|
+
<% if Array(attributes).detect { |a| a.type == :string || a.type == :text || a.type == :slug } -%>
|
13
21
|
import de.saumya.gwt.translation.gui.client.bindings.TextBoxBinding;
|
22
|
+
<% end -%>
|
14
23
|
|
15
24
|
public class <%= class_name %>Fields extends ResourceFields<<%= class_name %>> {
|
16
25
|
|
@@ -24,6 +33,8 @@ public class <%= class_name %>Fields extends ResourceFields<<%= class_name %>> {
|
|
24
33
|
public void pullFrom(final <%= class_name %> resource) {
|
25
34
|
<% if attribute.type == :boolean -%>
|
26
35
|
setValue(resource.<%= attribute.name.javanize %>);
|
36
|
+
<% elsif attribute.type == :date -%>
|
37
|
+
setValue(resource.<%= attribute.name.javanize %>.toString());
|
27
38
|
<% else -%>
|
28
39
|
setText(resource.<%= attribute.name.javanize %>);
|
29
40
|
<% end -%>
|
@@ -33,6 +44,8 @@ public class <%= class_name %>Fields extends ResourceFields<<%= class_name %>> {
|
|
33
44
|
public void pushInto(final <%= class_name %> resource) {
|
34
45
|
<% if attribute.type == :boolean -%>
|
35
46
|
resource.<%= attribute.name.javanize %> = getValue();
|
47
|
+
<% elsif attribute.type == :date -%>
|
48
|
+
resource.<%= attribute.name.javanize %> = new TimestampFactory(getText()).toDate();
|
36
49
|
<% else -%>
|
37
50
|
resource.<%= attribute.name.javanize %> = getText<% if attribute.type == :integer %>AsInt<% end -%>();
|
38
51
|
<% end -%>
|
@@ -13,21 +13,21 @@ import java.sql.Timestamp;
|
|
13
13
|
import com.google.gwt.xml.client.Element;
|
14
14
|
|
15
15
|
import de.saumya.gwt.persistence.client.Repository;
|
16
|
-
import de.saumya.gwt.persistence.client.
|
16
|
+
import de.saumya.gwt.persistence.client.Resource;
|
17
17
|
<% unless options[:skip_modified_by] -%>
|
18
18
|
import de.saumya.gwt.session.client.models.User;
|
19
19
|
import de.saumya.gwt.session.client.models.UserFactory;
|
20
20
|
<% end -%>
|
21
21
|
|
22
|
-
public class <%= class_name %> extends
|
22
|
+
public class <%= class_name %> extends Resource<<%= class_name %>> {
|
23
23
|
|
24
24
|
<% unless options[:skip_modified_by] -%>
|
25
25
|
private final UserFactory userFactory;
|
26
26
|
|
27
27
|
<% end -%>
|
28
28
|
protected <%= class_name %>(final Repository repository, final <%= class_name %>Factory factory<% unless options[:skip_modified_by] -%>,
|
29
|
-
|
30
|
-
super(repository, factory);
|
29
|
+
final UserFactory userFactory<% end -%>, final int id) {
|
30
|
+
super(repository, factory, id);
|
31
31
|
<% unless options[:skip_modified_by] -%>
|
32
32
|
this.userFactory = userFactory;
|
33
33
|
<% end -%>
|
@@ -47,7 +47,6 @@ public class <%= class_name %> extends ResourceWithID<<%= class_name %>> {
|
|
47
47
|
|
48
48
|
@Override
|
49
49
|
protected void appendXml(final StringBuilder buf) {
|
50
|
-
super.appendXml(buf);
|
51
50
|
<% Array(attributes).each do |attribute| -%>
|
52
51
|
appendXml(buf, "<%= attribute.name %>", this.<%= attribute.name.javanize %>);
|
53
52
|
<% end -%>
|
@@ -62,8 +61,7 @@ public class <%= class_name %> extends ResourceWithID<<%= class_name %>> {
|
|
62
61
|
}
|
63
62
|
|
64
63
|
@Override
|
65
|
-
protected void
|
66
|
-
super.fromXml(root);
|
64
|
+
protected void fromElement(final Element root) {
|
67
65
|
<% Array(attributes).each do |attribute| -%>
|
68
66
|
this.<%= attribute.name.javanize %> = get<% if attribute.type == :date %>Date<% elsif attribute.type == :integer %>Int<% elsif attribute.type == :boolean %>Boolean<% else %>String<% end -%>(root, "<%= attribute.name %>");
|
69
67
|
<% end -%>
|
@@ -78,18 +76,17 @@ public class <%= class_name %> extends ResourceWithID<<%= class_name %>> {
|
|
78
76
|
}
|
79
77
|
|
80
78
|
@Override
|
81
|
-
public void toString(final StringBuilder buf) {
|
82
|
-
super.toString(buf);
|
79
|
+
public void toString(final String indent, final StringBuilder buf) {
|
83
80
|
<% Array(attributes).each do |attribute| -%>
|
84
|
-
toString(buf, "<%= attribute.name %>", this.<%= attribute.name.javanize %>);
|
81
|
+
toString(indent, buf, "<%= attribute.name %>", this.<%= attribute.name.javanize %>);
|
85
82
|
<% end -%>
|
86
83
|
<% unless options[:skip_timestamps] -%>
|
87
|
-
toString(buf, "created_at", this.createdAt);
|
88
|
-
toString(buf, "updated_at", this.updatedAt);
|
84
|
+
toString(indent, buf, "created_at", this.createdAt);
|
85
|
+
toString(indent, buf, "updated_at", this.updatedAt);
|
89
86
|
<% end -%>
|
90
87
|
<% unless options[:skip_modified_by] -%>
|
91
|
-
toString(buf, "created_by", this.createdBy);
|
92
|
-
toString(buf, "updated_by", this.updatedBy);
|
88
|
+
toString(indent, buf, "created_by", this.createdBy);
|
89
|
+
toString(indent, buf, "updated_by", this.updatedBy);
|
93
90
|
<% end -%>
|
94
91
|
}
|
95
92
|
|
@@ -28,13 +28,8 @@ public class <%= class_name %>Factory extends ResourceFactory<<%= class_name %>>
|
|
28
28
|
}
|
29
29
|
|
30
30
|
@Override
|
31
|
-
public
|
32
|
-
return
|
33
|
-
}
|
34
|
-
|
35
|
-
@Override
|
36
|
-
public <%= class_name %> newResource() {
|
37
|
-
return new <%= class_name %>(this.repository, this<% unless options[:skip_modified_by] -%>, this.userFactory<% end -%>);
|
31
|
+
public <%= class_name %> newResource(final int id) {
|
32
|
+
return new <%= class_name %>(this.repository, this<% unless options[:skip_modified_by] -%>, this.userFactory<% end -%>, id);
|
38
33
|
}
|
39
34
|
|
40
35
|
@Override
|
@@ -6,11 +6,12 @@ package <%= package %>.views.<%= plural_name %>;
|
|
6
6
|
import <%= package %>.models.<%= class_name %>;
|
7
7
|
import <%= package %>.models.<%= class_name %>Factory;
|
8
8
|
|
9
|
-
import de.saumya.gwt.persistence.client.ResourceNotifications;
|
10
9
|
import de.saumya.gwt.session.client.Session;
|
11
10
|
import de.saumya.gwt.translation.common.client.GetTextController;
|
12
|
-
import de.saumya.gwt.translation.common.client.widget.
|
11
|
+
import de.saumya.gwt.translation.common.client.widget.HyperlinkFactory;
|
13
12
|
import de.saumya.gwt.translation.common.client.widget.LoadingNotice;
|
13
|
+
import de.saumya.gwt.translation.common.client.widget.NotificationListeners;
|
14
|
+
import de.saumya.gwt.translation.common.client.widget.ResourceActionPanel;
|
14
15
|
import de.saumya.gwt.translation.common.client.widget.ResourceBindings;
|
15
16
|
import de.saumya.gwt.translation.common.client.widget.ResourceCollectionListing;
|
16
17
|
import de.saumya.gwt.translation.common.client.widget.ResourceCollectionNavigation;
|
@@ -36,7 +37,8 @@ public class <%= class_name %>Screen extends ResourceScreen<<%= class_name %>> {
|
|
36
37
|
final GetTextController getTextController,
|
37
38
|
final <%= class_name %>Factory factory, final Session session,
|
38
39
|
final ResourceBindings<<%= class_name %>> bindings,
|
39
|
-
final
|
40
|
+
final NotificationListeners listeners,
|
41
|
+
final HyperlinkFactory hyperlinkFactory) {
|
40
42
|
super(loadingNotice,
|
41
43
|
factory,
|
42
44
|
session,
|
@@ -48,13 +50,18 @@ public class <%= class_name %>Screen extends ResourceScreen<<%= class_name %>> {
|
|
48
50
|
getTextController),
|
49
51
|
new ResourceCollectionListing<<%= class_name %>>(session,
|
50
52
|
factory,
|
51
|
-
getTextController
|
52
|
-
|
53
|
+
getTextController,
|
54
|
+
hyperlinkFactory)),
|
55
|
+
new ResourceActionPanel<<%= class_name %>>(getTextController,
|
53
56
|
bindings,
|
54
57
|
session,
|
55
58
|
factory,
|
56
|
-
|
57
|
-
|
59
|
+
listeners,
|
60
|
+
hyperlinkFactory,
|
61
|
+
true,
|
62
|
+
true),
|
63
|
+
listeners,
|
64
|
+
hyperlinkFactory);
|
58
65
|
}
|
59
66
|
|
60
67
|
}
|
@@ -11,7 +11,7 @@ import de.saumya.gwt.persistence.client.ResourceFactory;
|
|
11
11
|
*/
|
12
12
|
public class <%= class_name %>TestGwt extends AbstractApplicationResourceTestGwt<<%= class_name %>> {
|
13
13
|
|
14
|
-
|
14
|
+
<% first = attributes.detect {|a| a.type == :string } || attributes.first -%>
|
15
15
|
private <%= class_name %> resource;
|
16
16
|
|
17
17
|
private static final String RESOURCE_XML = "<<%= singular_name%>>"
|
@@ -53,10 +53,12 @@ public class <%= class_name %>TestGwt extends AbstractApplicationResourceTestGwt
|
|
53
53
|
|
54
54
|
@Override
|
55
55
|
protected Resource<<%= class_name %>> resourceSetUp() {
|
56
|
-
this.resource = this.factory.newResource();
|
56
|
+
this.resource = this.factory.newResource(idValue());
|
57
57
|
|
58
58
|
this.resource.id = 1;
|
59
|
-
|
59
|
+
<% Array(attributes).each do |attribute| -%>
|
60
|
+
this.resource.<%= attribute.name.javanize %> = <% if [:date, :time, :date_time].member? attribute.type %>new de.saumya.gwt.persistence.client.TimestampFactory("<%= attribute.sample_value %>").to<%= attribute.type == :date_time ? "Timestamp" : attribute.type.to_s.constantize %>()<% elsif [:integer, :float, :decimal, :big_decimal, :boolean].member? attribute.type %><%= attribute.sample_value %><% else %>"<%= attribute.sample_value %>"<% end -%>;
|
61
|
+
<% end -%>
|
60
62
|
|
61
63
|
this.repository.addXmlResponse(RESOURCE_XML);
|
62
64
|
|
@@ -67,14 +69,14 @@ public class <%= class_name %>TestGwt extends AbstractApplicationResourceTestGwt
|
|
67
69
|
|
68
70
|
@Override
|
69
71
|
public void doTestCreate() {
|
70
|
-
assertEquals("<%=
|
72
|
+
assertEquals("<%= first.sample_value %>", this.resource.<%= first.name.javanize %><% if [:date, :time, :date_time].member? first.type %>.toString()<% end -%>);
|
71
73
|
}
|
72
74
|
|
73
75
|
@Override
|
74
76
|
public void doTestUpdate() {
|
75
|
-
this.resource.<%=
|
77
|
+
this.resource.<%= first.name.javanize %> = <% if [:date, :time, :date_time].member? first.type %>new de.saumya.gwt.persistence.client.TimestampFactory(changedValue()).toDate()<% else %>changedValue()<% end -%>;
|
76
78
|
this.resource.save();
|
77
|
-
assertEquals(this.resource.<%=
|
79
|
+
assertEquals(this.resource.<%= first.name.javanize %><% if [:date, :time, :date_time].member? first.type %>.toString()<% end -%>, changedValue());
|
78
80
|
}
|
79
81
|
|
80
82
|
private final static String XML = "<<%= singular_name%>>"
|
@@ -90,12 +92,12 @@ public class <%= class_name %>TestGwt extends AbstractApplicationResourceTestGwt
|
|
90
92
|
|
91
93
|
@Override
|
92
94
|
protected String changedValue() {
|
93
|
-
return "<%=
|
95
|
+
return "<%= first.sample_value(false) %>";
|
94
96
|
}
|
95
97
|
|
96
98
|
@Override
|
97
|
-
protected
|
98
|
-
return
|
99
|
+
protected int idValue() {
|
100
|
+
return 1;
|
99
101
|
}
|
100
102
|
|
101
103
|
@Override
|
@@ -105,6 +107,6 @@ public class <%= class_name %>TestGwt extends AbstractApplicationResourceTestGwt
|
|
105
107
|
|
106
108
|
@Override
|
107
109
|
protected String value() {
|
108
|
-
return "<%=
|
110
|
+
return "<%= first.sample_value %>";
|
109
111
|
}
|
110
112
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
migration <%= Time.now.utc.strftime("%Y%m%d%H%M%S") %>, :<%= migration_name.underscore %> do
|
2
|
+
up do
|
3
|
+
create_table :<%= table_name %> do
|
4
|
+
column :id, Integer, :serial => true
|
5
|
+
<% Array(attributes).each do |attribute| -%>
|
6
|
+
column :<%= attribute.name if attribute %>, <%= attribute.type == :boolean ? "::DataMapper::Types::Boolean" : attribute.type.to_s.capitalize %>, :nullable => false<% if attribute.type == :string %>, :length => 255<% end %>
|
7
|
+
<% end -%>
|
8
|
+
<% unless options[:skip_timestamps] -%>
|
9
|
+
column :created_at, DateTime, :nullable => false
|
10
|
+
column :updated_at, DateTime, :nullable => false
|
11
|
+
<% end -%>
|
12
|
+
<% unless options[:skip_modified_by] -%>
|
13
|
+
column :created_by_id, Integer, :nullable => false
|
14
|
+
column :updated_by_id, Integer, :nullable => false
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
down do
|
20
|
+
drop_table :<%= table_name %>
|
21
|
+
end
|
22
|
+
end
|
@@ -3,7 +3,7 @@ class <%= class_name %>
|
|
3
3
|
|
4
4
|
property :id, Serial
|
5
5
|
<% Array(attributes).each do |attribute| -%>
|
6
|
-
property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :
|
6
|
+
property :<%= attribute.name %>, <%= attribute.type == :boolean ? "::DataMapper::Types::Boolean" : attribute.type.to_s.capitalize %>, :required => true<% if attribute.type == :string or attribute.type == :text or attribute.type == :slug -%>, :format => /^[^<'&">]*$/<% if attribute.type == :string or attribute.type == :slug %>, :length => 255<% end -%><% end -%>
|
7
7
|
|
8
8
|
<% end -%>
|
9
9
|
<% unless options[:skip_timestamps] -%>
|
@@ -11,7 +11,7 @@ class <%= class_name %>
|
|
11
11
|
<% end -%>
|
12
12
|
|
13
13
|
<% unless options[:skip_modified_by] -%>
|
14
|
-
modified_by
|
14
|
+
modified_by Ixtlan::Models::USER
|
15
15
|
|
16
16
|
require 'dm-serializer'
|
17
17
|
alias :to_x :to_xml_document
|
@@ -16,5 +16,7 @@ class IxtlanDatamapperRspecModelGenerator < DatamapperRspecModelGenerator
|
|
16
16
|
"Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
|
17
17
|
opt.on("--skip-modified-by",
|
18
18
|
"Don't add modified_by references for this model") { |v| options[:skip_modified_by] = v }
|
19
|
+
opt.on("--add-current-user",
|
20
|
+
"set current user before invoking a method on the model") { |v| options[:current_user] = v }
|
19
21
|
end
|
20
22
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
-
|
2
|
+
<% if !options[:skip_modified_by] || options[:current_user] -%>
|
3
|
+
USER = Object.full_const_get(Ixtlan::Models::USER) unless Object.const_defined? "USER"
|
4
|
+
<% end -%>
|
3
5
|
describe <%= class_name %> do
|
4
6
|
before(:each) do
|
5
|
-
<%
|
6
|
-
user =
|
7
|
+
<% if !options[:skip_modified_by] || options[:current_user] -%>
|
8
|
+
user = USER.first
|
7
9
|
unless user
|
8
|
-
user =
|
10
|
+
user = USER.new(:login => 'root', :email => 'root@exmple.com', :name => 'Superuser', :language => 'en', :id => 1, :created_at => DateTime.now, :updated_at => DateTime.now)
|
9
11
|
user.created_by_id = 1
|
10
12
|
user.updated_by_id = 1
|
11
13
|
user.save!
|
12
14
|
end
|
13
15
|
<% end -%>
|
14
16
|
@valid_attributes = {
|
15
|
-
<%
|
17
|
+
<% if !options[:skip_modified_by] || options[:current_user] -%>
|
16
18
|
:current_user => user,
|
17
19
|
<% end -%>
|
18
20
|
<% attributes.each_with_index do |attribute, attribute_index| -%>
|
@@ -22,6 +24,7 @@ describe <%= class_name %> do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it "should create a new instance given valid attributes" do
|
27
|
+
<%= class_name %>.all(:<%= attributes.first.name %> => <%= attributes.first.default_value %>).destroy!
|
25
28
|
<%= singular_name %> = <%= class_name %>.create(@valid_attributes)
|
26
29
|
<%= singular_name %>.valid?.should be_true
|
27
30
|
end
|
data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb
CHANGED
@@ -29,6 +29,8 @@ class IxtlanDatamapperRspecScaffoldGenerator < DatamapperRspecScaffoldGenerator
|
|
29
29
|
"Don't add timestamps for this model") { |v| options[:skip_timestamps] = v }
|
30
30
|
opt.on("--skip-modified-by",
|
31
31
|
"Don't add modified_by references for this model") { |v| options[:skip_modified_by] = v }
|
32
|
+
opt.on("--add-current-user",
|
33
|
+
"set current user before invoking a method on the model") { |v| options[:current_user] = v }
|
32
34
|
opt.on("--skip-guard",
|
33
35
|
"Don't add guards for the actions on this model") { |v| options[:add_guard] = v }
|
34
36
|
opt.on("--i18n",
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
-
|
2
|
+
<% if !options[:skip_modified_by] || options[:current_user] -%>
|
3
|
+
CONFIGURATION = Object.full_const_get(Ixtlan::Models::CONFIGURATION) unless Object.const_defined? "CONFIGURATION"
|
4
|
+
<% end -%>
|
3
5
|
describe <%= controller_class_name %>Controller do
|
4
6
|
|
5
7
|
def mock_<%= file_name %>(stubs={})
|
@@ -16,8 +18,8 @@ describe <%= controller_class_name %>Controller do
|
|
16
18
|
|
17
19
|
def mock_arguments(merge = {})
|
18
20
|
args = merge
|
19
|
-
<%
|
20
|
-
args.merge!(:current_user= => nil)
|
21
|
+
<% if !options[:skip_modified_by] || options[:current_user] -%>
|
22
|
+
args.merge!(:current_user= => nil, :errors => {})
|
21
23
|
<% end -%>
|
22
24
|
<% unless options[:skip_audit] -%>
|
23
25
|
args.merge!(:model => <%= class_name %>, :key => 12)
|
@@ -27,13 +29,17 @@ describe <%= controller_class_name %>Controller do
|
|
27
29
|
|
28
30
|
<% unless options[:skip_guard] -%>
|
29
31
|
before(:each) do
|
30
|
-
user =
|
32
|
+
user = Object.new
|
33
|
+
def user.id; 1; end
|
34
|
+
def user.login; "root"; end
|
31
35
|
def user.groups
|
32
|
-
|
36
|
+
g = Object.new
|
37
|
+
def g.name; "root"; end
|
38
|
+
[g]
|
33
39
|
end
|
34
40
|
controller.send(:current_user=, user)
|
35
|
-
mock_configuration = mock_model(
|
36
|
-
|
41
|
+
mock_configuration = mock_model(CONFIGURATION,{})
|
42
|
+
CONFIGURATION.should_receive(:instance).any_number_of_times.and_return(mock_configuration)
|
37
43
|
mock_configuration.should_receive(:session_idle_timeout).any_number_of_times.and_return(1)
|
38
44
|
end
|
39
45
|
<% end -%>
|
data/lib/dm-serializer/to_xml.rb
CHANGED
@@ -26,8 +26,8 @@ module DataMapper
|
|
26
26
|
root = xml.root_node(doc, opts[:element_name] || default_xml_element_name[])
|
27
27
|
properties_to_serialize(opts).each do |property|
|
28
28
|
value = __send__(property.name)
|
29
|
-
attrs = (property.
|
30
|
-
value = value.to_s(:xml) if property.
|
29
|
+
attrs = (property.class == DataMapper::Property::String) ? {} : {'type' => property.class.to_s.downcase}
|
30
|
+
value = value.to_s(:xml) if property.class == DataMapper::Property::DateTime rescue value
|
31
31
|
xml.add_node(root, property.name.to_s, value.frozen? ? value.to_s.dup: value, attrs)
|
32
32
|
end
|
33
33
|
|
@@ -19,7 +19,7 @@ module Ixtlan
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def destroy
|
22
|
-
authentication_logger.log_user(current_user.nil? ? nil : current_user.login, "
|
22
|
+
authentication_logger.log_user(current_user.nil? ? nil : current_user.login, "logged out")
|
23
23
|
session.clear
|
24
24
|
head :ok
|
25
25
|
end
|
@@ -9,9 +9,11 @@ module Ixtlan
|
|
9
9
|
USER = Object.full_const_get(::Ixtlan::Models::USER)
|
10
10
|
|
11
11
|
def adjust_params(user_params)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if user_params
|
13
|
+
lang = user_params.delete(:preferred_language)
|
14
|
+
user_params[:language] = lang[:code][0..1] if lang
|
15
|
+
user_params.delete(:groups)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
public
|
@@ -12,8 +12,6 @@ module Ixtlan
|
|
12
12
|
|
13
13
|
model.property :password, String,:format => /^[a-zA-Z0-9_.]*$/
|
14
14
|
|
15
|
-
model.send :attr_accessor, :token
|
16
|
-
|
17
15
|
model.belongs_to :user, :model => ::Ixtlan::Models::USER
|
18
16
|
|
19
17
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -23,7 +21,7 @@ module Ixtlan
|
|
23
21
|
|
24
22
|
alias :to_x :to_xml_document
|
25
23
|
def to_xml_document(opts, doc = nil)
|
26
|
-
opts.merge!({:exclude => [:password,:user_id], :methods => [:
|
24
|
+
opts.merge!({:exclude => [:password,:user_id], :methods => [:user]})
|
27
25
|
to_x(opts, doc)
|
28
26
|
end
|
29
27
|
end
|
@@ -62,14 +62,14 @@ module Ixtlan
|
|
62
62
|
params[:approved_at] = attribute_get(:updated_at)
|
63
63
|
params[:approved_by] = params[:current_user] || current_user
|
64
64
|
|
65
|
-
|
65
|
+
prev = (previous.nil? ? true : previous.update(:previous => false,
|
66
66
|
:current_user => params[:current_user] || current_user))
|
67
|
-
|
67
|
+
lat = (latest.nil? ? true : latest.update(:current => false,
|
68
68
|
:previous => true,
|
69
69
|
:current_user => params[:current_user] || current_user))
|
70
|
-
|
70
|
+
upd = update(params)
|
71
71
|
|
72
|
-
|
72
|
+
upd && lat && prev
|
73
73
|
end
|
74
74
|
|
75
75
|
def approved?
|
data/lib/ixtlan/models/user.rb
CHANGED
data/lib/ixtlan/models/word.rb
CHANGED
data/lib/ixtlan/modified_by.rb
CHANGED
@@ -59,7 +59,7 @@ module Ixtlan
|
|
59
59
|
module ClassMethods
|
60
60
|
def modified_by(type, names = nil, options = {})
|
61
61
|
if(names.nil?)
|
62
|
-
modified_by(type, [:created_by, :updated_by])
|
62
|
+
modified_by(type, [:created_by, :updated_by], options)
|
63
63
|
else
|
64
64
|
names = [names] unless names.is_a?(Enumerable)
|
65
65
|
names.each do |name|
|
@@ -1,18 +1,15 @@
|
|
1
1
|
require 'ixtlan/optimistic_persistence_module'
|
2
2
|
require 'dm-core'
|
3
|
-
module
|
3
|
+
module Ixtlan
|
4
4
|
|
5
5
|
class StaleResourceError < StandardError; end
|
6
6
|
|
7
|
-
end
|
8
|
-
|
9
|
-
module Ixtlan
|
10
7
|
module OptimisticPersistence
|
11
8
|
|
12
9
|
def self.included(base)
|
13
10
|
base.send(:include, ::Ixtlan::OptimisticPersistenceModule)
|
14
11
|
base.before :valid? do
|
15
|
-
raise
|
12
|
+
raise StaleResourceError.new(model.name + "(#{key}) was stale") if stale?
|
16
13
|
end
|
17
14
|
end
|
18
15
|
::DataMapper::Model.append_inclusions self
|
@@ -3,27 +3,33 @@ module Ixtlan
|
|
3
3
|
class Migrations
|
4
4
|
|
5
5
|
# assume no namespaces !!!
|
6
|
-
USER = Object.const_get(Ixtlan::Models::USER)
|
7
|
-
GROUP = Object.const_get(Ixtlan::Models::GROUP)
|
8
|
-
LOCALE = Object.const_get(Ixtlan::Models::LOCALE)
|
9
|
-
DOMAIN = Object.const_get(Ixtlan::Models::DOMAIN)
|
10
|
-
CONFIGURATION = Object.const_get(Ixtlan::Models::CONFIGURATION)
|
6
|
+
USER = Object.const_get(Ixtlan::Models::USER.sub(/^::/, ''))
|
7
|
+
GROUP = Object.const_get(Ixtlan::Models::GROUP.sub(/^::/, ''))
|
8
|
+
LOCALE = Object.const_get(Ixtlan::Models::LOCALE.sub(/^::/, ''))
|
9
|
+
DOMAIN = Object.const_get(Ixtlan::Models::DOMAIN.sub(/^::/, ''))
|
10
|
+
CONFIGURATION = Object.const_get(Ixtlan::Models::CONFIGURATION.sub(/^::/, ''))
|
11
|
+
TEXT = Object.const_get(Ixtlan::Models::TEXT.sub(/^::/, ''))
|
11
12
|
|
12
13
|
def self.create_user
|
13
|
-
USER.
|
14
|
-
LOCALE.
|
15
|
-
GROUP.
|
16
|
-
Ixtlan::Models::GroupUser.
|
17
|
-
Ixtlan::Models::GroupLocaleUser.
|
18
|
-
Ixtlan::Models::DomainGroupUser.
|
19
|
-
|
20
|
-
u = USER.
|
21
|
-
u.
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
USER.auto_migrate!
|
15
|
+
LOCALE.auto_migrate!
|
16
|
+
GROUP.auto_migrate!
|
17
|
+
Ixtlan::Models::GroupUser.auto_migrate!
|
18
|
+
Ixtlan::Models::GroupLocaleUser.auto_migrate!
|
19
|
+
Ixtlan::Models::DomainGroupUser.auto_migrate!
|
20
|
+
|
21
|
+
u = USER.first
|
22
|
+
if u.nil?
|
23
|
+
u = USER.new(:login => 'root', :email => 'root@example.com', :name => 'Superuser', :id => 1)
|
24
|
+
u.created_at = DateTime.now
|
25
|
+
u.updated_at = u.created_at
|
26
|
+
u.created_by_id = 1
|
27
|
+
u.updated_by_id = 1
|
28
|
+
u.save!
|
29
|
+
end
|
25
30
|
u.reset_password
|
26
|
-
u.
|
31
|
+
u.current_user = u
|
32
|
+
u.save
|
27
33
|
|
28
34
|
g = GROUP.create(:name => 'root', :current_user => u)
|
29
35
|
u.groups << g
|
@@ -38,18 +44,17 @@ module Ixtlan
|
|
38
44
|
users = GROUP.create(:name => 'users', :current_user => u)
|
39
45
|
locales = GROUP.create(:name => 'locales', :current_user => u)
|
40
46
|
domains = GROUP.create(:name => 'domains', :current_user => u)
|
41
|
-
|
42
|
-
File.open("root", 'w') { |f| f.puts "root\n#{u.password}\n\nadmin\n#{a.password}\n\n" }
|
47
|
+
File.open("root_#{RAILS_ENV}", 'w') { |f| f.puts "root\n#{u.password}\n\nadmin\n#{a.password}\n\n" }
|
43
48
|
end
|
44
49
|
|
45
50
|
def self.create_configuration
|
46
|
-
Ixtlan::Models::ConfigurationLocale.
|
47
|
-
CONFIGURATION.
|
51
|
+
Ixtlan::Models::ConfigurationLocale.auto_migrate!
|
52
|
+
CONFIGURATION.auto_migrate!
|
48
53
|
CONFIGURATION.create(:session_idle_timeout => 10, :keep_audit_logs => 3, :current_user => USER.first)
|
49
54
|
end
|
50
55
|
|
51
56
|
def self.create_locale
|
52
|
-
LOCALE.
|
57
|
+
LOCALE.auto_migrate!
|
53
58
|
# get/create default locale
|
54
59
|
LOCALE.create(:code => LOCALE::DEFAULT, :current_user => USER.first)
|
55
60
|
# get/create "every" locale
|
@@ -60,7 +65,7 @@ module Ixtlan
|
|
60
65
|
end
|
61
66
|
|
62
67
|
def self.create_domain
|
63
|
-
DOMAIN.
|
68
|
+
DOMAIN.auto_migrate!
|
64
69
|
# get/create "every" domain
|
65
70
|
DOMAIN.create(:name => DOMAIN::ALL, :current_user => User.first)
|
66
71
|
|
@@ -68,7 +73,7 @@ module Ixtlan
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def self.create_text
|
71
|
-
|
76
|
+
TEXT.auto_migrate!
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
@@ -97,7 +97,7 @@ module Rails
|
|
97
97
|
authentication = AUTHENTICATION.new
|
98
98
|
authentication.login = self.current_user.login
|
99
99
|
authentication.user = self.current_user
|
100
|
-
authentication
|
100
|
+
response.headers["authentication-token"] = form_authenticity_token
|
101
101
|
render :xml => authentication.to_xml
|
102
102
|
end
|
103
103
|
end
|